Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,17 @@
|
|
| 1 |
import gradio as gr #importing gradio
|
| 2 |
-
import random
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
#all print statements will be shown in the log after committing the changes to the main.
|
| 7 |
-
chatbot = gr.ChatInterface(
|
| 8 |
chatbot.launch() # launches the chatbot.
|
|
|
|
| 1 |
import gradio as gr #importing gradio
|
| 2 |
+
import random as rn
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
+
client = InferenceClient("microsoft/phi-4")
|
| 5 |
+
def respond(message, history):
|
| 6 |
+
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
|
| 7 |
+
if history:
|
| 8 |
+
messages.extend("history")
|
| 9 |
+
messages.append({"role": "user", "content": message})
|
| 10 |
+
response = client.chat_completion(
|
| 11 |
+
messages,
|
| 12 |
+
max_tokens=100
|
| 13 |
+
)
|
| 14 |
+
return response['choices'][0]['message']['content'].strip()
|
| 15 |
#all print statements will be shown in the log after committing the changes to the main.
|
| 16 |
+
chatbot = gr.ChatInterface(respond, type = 'messages', title="Chatbot V2.0") #builds chatbot UI - conversation history and user input
|
| 17 |
chatbot.launch() # launches the chatbot.
|