Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -27,7 +27,7 @@ class ChatBot:
|
|
27 |
|
28 |
self.model = Together(
|
29 |
model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
|
30 |
-
temperature=0.1,
|
31 |
max_tokens=128,
|
32 |
top_k=30,
|
33 |
together_api_key=TOGETHER_API_KEY
|
@@ -39,7 +39,6 @@ class ChatBot:
|
|
39 |
output_key="answer"
|
40 |
)
|
41 |
|
42 |
-
# Updated prompt template with more specific instructions
|
43 |
self.template = """Quyidagi ko'rsatmalarga qat'iy rioya qiling:
|
44 |
|
45 |
1. Faqat o'zbek tilida javob bering
|
@@ -79,12 +78,16 @@ Javob:"""
|
|
79 |
|
80 |
response = re.sub(r"```.*?```", "", response, flags=re.DOTALL)
|
81 |
response = re.sub(r"print\(.*?\)", "", response)
|
82 |
-
response = re.sub(r'\s+', ' ', response)
|
83 |
-
|
84 |
return response.strip()
|
85 |
|
86 |
def chat(self, message: str, history: List[Tuple[str, str]]) -> str:
|
87 |
try:
|
|
|
|
|
|
|
|
|
88 |
self.memory.chat_memory.add_user_message(message)
|
89 |
response = self.chain.invoke(message)
|
90 |
clean_response = self.process_response(response)
|
@@ -108,10 +111,10 @@ def create_demo() -> gr.Interface:
|
|
108 |
gr.Markdown("""# RAG Chatbot
|
109 |
Beeline Uzbekistanning jismoniy shaxslar uchun tariflari haqida ma'lumotlar beruvchi bot""")
|
110 |
|
|
|
111 |
chatbot_interface = gr.Chatbot(
|
112 |
height=600,
|
113 |
show_copy_button=True,
|
114 |
-
value=[("", "Assalomu alaykum. Sizga qanday yordam bera olaman?")] # Initial greeting
|
115 |
)
|
116 |
|
117 |
with gr.Row():
|
@@ -133,13 +136,17 @@ def create_demo() -> gr.Interface:
|
|
133 |
chat_history.append((message, bot_message))
|
134 |
return "", chat_history
|
135 |
|
136 |
-
def
|
137 |
-
|
138 |
-
|
|
|
139 |
|
140 |
submit.click(respond, [msg, chatbot_interface], [msg, chatbot_interface])
|
141 |
msg.submit(respond, [msg, chatbot_interface], [msg, chatbot_interface])
|
142 |
-
clear.click(
|
|
|
|
|
|
|
143 |
|
144 |
return demo
|
145 |
|
|
|
27 |
|
28 |
self.model = Together(
|
29 |
model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
|
30 |
+
temperature=0.1,
|
31 |
max_tokens=128,
|
32 |
top_k=30,
|
33 |
together_api_key=TOGETHER_API_KEY
|
|
|
39 |
output_key="answer"
|
40 |
)
|
41 |
|
|
|
42 |
self.template = """Quyidagi ko'rsatmalarga qat'iy rioya qiling:
|
43 |
|
44 |
1. Faqat o'zbek tilida javob bering
|
|
|
78 |
|
79 |
response = re.sub(r"```.*?```", "", response, flags=re.DOTALL)
|
80 |
response = re.sub(r"print\(.*?\)", "", response)
|
81 |
+
response = re.sub(r'\s+', ' ', response)
|
82 |
+
|
83 |
return response.strip()
|
84 |
|
85 |
def chat(self, message: str, history: List[Tuple[str, str]]) -> str:
|
86 |
try:
|
87 |
+
# Skip processing for the initial greeting
|
88 |
+
if message == "__init__":
|
89 |
+
return "Assalomu alaykum. Sizga qanday yordam bera olaman?"
|
90 |
+
|
91 |
self.memory.chat_memory.add_user_message(message)
|
92 |
response = self.chain.invoke(message)
|
93 |
clean_response = self.process_response(response)
|
|
|
111 |
gr.Markdown("""# RAG Chatbot
|
112 |
Beeline Uzbekistanning jismoniy shaxslar uchun tariflari haqida ma'lumotlar beruvchi bot""")
|
113 |
|
114 |
+
# Initialize the chatbot interface without the greeting
|
115 |
chatbot_interface = gr.Chatbot(
|
116 |
height=600,
|
117 |
show_copy_button=True,
|
|
|
118 |
)
|
119 |
|
120 |
with gr.Row():
|
|
|
136 |
chat_history.append((message, bot_message))
|
137 |
return "", chat_history
|
138 |
|
139 |
+
def init_chat():
|
140 |
+
# Initialize with greeting
|
141 |
+
initial_greeting = chatbot.chat("__init__", [])
|
142 |
+
return [("", initial_greeting)]
|
143 |
|
144 |
submit.click(respond, [msg, chatbot_interface], [msg, chatbot_interface])
|
145 |
msg.submit(respond, [msg, chatbot_interface], [msg, chatbot_interface])
|
146 |
+
clear.click(init_chat, None, chatbot_interface)
|
147 |
+
|
148 |
+
# Set initial greeting when the interface loads
|
149 |
+
demo.load(init_chat, None, chatbot_interface)
|
150 |
|
151 |
return demo
|
152 |
|