added def response
Browse files
app.py
CHANGED
|
@@ -2,4 +2,29 @@ import gradio as gr
|
|
| 2 |
import huggingface_hub import InterferenceClient
|
| 3 |
import knowledgebase.txt
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
|
|
|
| 2 |
import huggingface_hub import InterferenceClient
|
| 3 |
import knowledgebase.txt
|
| 4 |
|
| 5 |
+
client = InterferenceClient("google/gemma-3-27b-it")
|
| 6 |
+
|
| 7 |
+
def respond(message,history):
|
| 8 |
+
messages = [{"role": "system" , "content", "You're a supportive and helpful feminist"}]
|
| 9 |
+
if history:
|
| 10 |
+
messages.extend(history)
|
| 11 |
+
|
| 12 |
+
messages.append({"role" : "user", "content" : message})
|
| 13 |
+
|
| 14 |
+
response = ""
|
| 15 |
+
for message in client.chat_completion(
|
| 16 |
+
messages,
|
| 17 |
+
max_tokens = 150,
|
| 18 |
+
stream=True,
|
| 19 |
+
):
|
| 20 |
+
token = message.choices[0].delta.content
|
| 21 |
+
response += token
|
| 22 |
+
yield response
|
| 23 |
+
|
| 24 |
+
print(response)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
chatbot = gr.ChatInterface(respond, type = "messages")
|
| 28 |
+
|
| 29 |
+
chatbot.launch(debug=True)
|
| 30 |
|