Spaces:
Sleeping
Sleeping
Turned Random into General ChatBot
Browse filesTOOK AWAY random output and replaces with relevant ig now its more generative and transformed
app.py
CHANGED
|
@@ -1,9 +1,23 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import random as rn
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
#import random as rn
|
| 3 |
+
from huggingface_hub import InterferenceClient
|
| 4 |
+
|
| 5 |
+
client = IterferenceClient("microsoft/phi-4")
|
| 6 |
+
|
| 7 |
+
def respond(message, history):
|
| 8 |
+
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
|
| 9 |
+
|
| 10 |
+
if history:
|
| 11 |
+
message.extend(history)
|
| 12 |
+
|
| 13 |
+
messages.append ({"role": "user", "content":message})
|
| 14 |
+
|
| 15 |
+
responses = client.chat_completion(
|
| 16 |
+
messages,
|
| 17 |
+
max_token=100
|
| 18 |
+
)
|
| 19 |
+
return response['choices'][0]['message']['content'].strip() #added here
|
| 20 |
+
|
| 21 |
+
chatbot = gr.ChatInterface(respond, type="messages", title="Friendly ChatBot") #chatbot UI - convo history & user input
|
| 22 |
+
|
| 23 |
+
chatbot.launch()
|