create a new chatbot RAG
Browse files
app.py
CHANGED
|
@@ -1,16 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
chatbot.launch()
|
|
|
|
| 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 repond(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 |
+
|
| 17 |
+
#return random.choice(responses)
|
| 18 |
+
response = client.chat_completion(
|
| 19 |
+
messages
|
| 20 |
+
max_tokens=100
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
return response['choices'][0]['message']['content'].strip()
|
| 24 |
+
|
| 25 |
+
chatbot = gr.ChatInterface(respond, type="messages")
|
| 26 |
+
|
| 27 |
+
#chatbot = gr.ChatInterface(
|
| 28 |
+
# fn=simple,
|
| 29 |
+
# title="Simple Pattern Bot",
|
| 30 |
+
# description="I respond to basic patterns (try saying hi or asking a question)",
|
| 31 |
+
# examples=["Hello", "How are you?", "What's your name?"],
|
| 32 |
+
#)
|
| 33 |
+
|
| 34 |
+
#if __name__ == "__main__":
|
| 35 |
chatbot.launch()
|