Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,9 @@ import logging
|
|
12 |
from typing import List, Tuple
|
13 |
from dataclasses import dataclass
|
14 |
from datetime import datetime
|
|
|
|
|
|
|
15 |
|
16 |
# Configure logging
|
17 |
logging.basicConfig(level=logging.INFO)
|
@@ -98,13 +101,23 @@ retriever = db.as_retriever(
|
|
98 |
search_kwargs={"k": 5}
|
99 |
)
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
# Set up the LLM
|
102 |
-
llm = ChatOpenAI(
|
103 |
-
base_url="https://api-inference.huggingface.co/v1/",
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
)
|
108 |
|
109 |
# Create prompt template with chat history
|
110 |
template = """
|
@@ -144,6 +157,7 @@ def create_rag_chain(chat_history: str):
|
|
144 |
chat_history = ChatHistory()
|
145 |
|
146 |
# Gradio Function
|
|
|
147 |
def ask_question_gradio(question, history):
|
148 |
try:
|
149 |
# Add user question to chat history
|
|
|
12 |
from typing import List, Tuple
|
13 |
from dataclasses import dataclass
|
14 |
from datetime import datetime
|
15 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
16 |
+
import spaces
|
17 |
+
|
18 |
|
19 |
# Configure logging
|
20 |
logging.basicConfig(level=logging.INFO)
|
|
|
101 |
search_kwargs={"k": 5}
|
102 |
)
|
103 |
|
104 |
+
|
105 |
+
# Load model directly
|
106 |
+
|
107 |
+
model_id="CohereForAI/c4ai-command-r7b-12-2024"
|
108 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
109 |
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
110 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
111 |
+
llm = HuggingFacePipeline(pipeline=pipe)
|
112 |
+
|
113 |
+
|
114 |
# Set up the LLM
|
115 |
+
#llm = ChatOpenAI(
|
116 |
+
# base_url="https://api-inference.huggingface.co/v1/",
|
117 |
+
# temperature=0,
|
118 |
+
# api_key=HF_TOKEN,
|
119 |
+
# model="meta-llama/Llama-3.3-70B-Instruct"
|
120 |
+
#)
|
121 |
|
122 |
# Create prompt template with chat history
|
123 |
template = """
|
|
|
157 |
chat_history = ChatHistory()
|
158 |
|
159 |
# Gradio Function
|
160 |
+
@spaces.GPU
|
161 |
def ask_question_gradio(question, history):
|
162 |
try:
|
163 |
# Add user question to chat history
|