fix RAG
Browse files
app.py
CHANGED
|
@@ -1,28 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
import os
|
| 4 |
-
|
| 5 |
#os.environ["HF_TOKEN"] = "#insert token here"
|
| 6 |
|
| 7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
| 9 |
-
def
|
| 10 |
messages = [{"role": "system","content": "You are a freindly chatbot!"}]
|
| 11 |
#responses = ["Hello", "How are you?", "What's your name?"]
|
| 12 |
if history:
|
| 13 |
message.extend(history)
|
| 14 |
|
| 15 |
messages.append({"role": "user", "content": message})
|
| 16 |
-
|
| 17 |
#return random.choice(responses)
|
| 18 |
response = client.chat_completion(
|
| 19 |
messages
|
| 20 |
max_tokens=100
|
| 21 |
)
|
| 22 |
|
| 23 |
-
return response[
|
| 24 |
|
| 25 |
-
chatbot = gr.ChatInterface(respond, type="messages")
|
| 26 |
|
| 27 |
#chatbot = gr.ChatInterface(
|
| 28 |
# fn=simple,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
import os
|
| 4 |
+
from huggingface_hub import InferenceClient
|
| 5 |
#os.environ["HF_TOKEN"] = "#insert token here"
|
| 6 |
|
| 7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
| 9 |
+
def respond(message, history):
|
| 10 |
messages = [{"role": "system","content": "You are a freindly chatbot!"}]
|
| 11 |
#responses = ["Hello", "How are you?", "What's your name?"]
|
| 12 |
if history:
|
| 13 |
message.extend(history)
|
| 14 |
|
| 15 |
messages.append({"role": "user", "content": message})
|
|
|
|
| 16 |
#return random.choice(responses)
|
| 17 |
response = client.chat_completion(
|
| 18 |
messages
|
| 19 |
max_tokens=100
|
| 20 |
)
|
| 21 |
|
| 22 |
+
return response["choices"][0]["message"]["content"].strip()
|
| 23 |
|
| 24 |
+
chatbot = gr.ChatInterface(respond, type = "messages")
|
| 25 |
|
| 26 |
#chatbot = gr.ChatInterface(
|
| 27 |
# fn=simple,
|