Spaces:
Sleeping
Sleeping
Connected Chatbot to LLM
Browse files
app.py
CHANGED
|
@@ -2,8 +2,27 @@ import gradio as gr
|
|
| 2 |
import random
|
| 3 |
#import lines go at the top!
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
#def echo(message, history):
|
| 9 |
#always need two inputs
|
|
@@ -11,7 +30,7 @@ def yes_or_no(message,history):
|
|
| 11 |
|
| 12 |
print("Hello, World")
|
| 13 |
|
| 14 |
-
chatbot = gr.ChatInterface(
|
| 15 |
#defining my chatbot so user can interact, see their conversation and send new messages
|
| 16 |
|
| 17 |
chatbot.launch()
|
|
|
|
| 2 |
import random
|
| 3 |
#import lines go at the top!
|
| 4 |
|
| 5 |
+
from huggingface_hub import InferenceClient
|
| 6 |
+
|
| 7 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
+
# name of llm chatbot accessed ^^
|
| 9 |
+
|
| 10 |
+
def respond(message,history):
|
| 11 |
+
|
| 12 |
+
messages = [{'role': 'system','content':'You are a friendly chatbot.'}]
|
| 13 |
+
#creating dictionary containing key value pairs; first key value pair is system message, second is user message
|
| 14 |
+
|
| 15 |
+
if history:
|
| 16 |
+
messages.extend(history)
|
| 17 |
+
|
| 18 |
+
messages.append({'role': 'user','content': message})
|
| 19 |
+
|
| 20 |
+
response = client.chat_completion(messages, max_tokens = 100)
|
| 21 |
+
|
| 22 |
+
return response['choices'][0]['message']['content'].strip()
|
| 23 |
+
|
| 24 |
+
#def yes_or_no(message,history):
|
| 25 |
+
#return random.choice(['Yes','No'])
|
| 26 |
|
| 27 |
#def echo(message, history):
|
| 28 |
#always need two inputs
|
|
|
|
| 30 |
|
| 31 |
print("Hello, World")
|
| 32 |
|
| 33 |
+
chatbot = gr.ChatInterface(respond, type='messages')
|
| 34 |
#defining my chatbot so user can interact, see their conversation and send new messages
|
| 35 |
|
| 36 |
chatbot.launch()
|