Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,37 +2,35 @@ from huggingface_hub import InferenceClient
|
|
| 2 |
import gradio as gr
|
| 3 |
import random
|
| 4 |
|
| 5 |
-
client = InferenceClient("google/gemma-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
if history:
|
| 12 |
-
for user_msg, bot_msg in history:
|
| 13 |
-
messages.append({"role": "user", "content": user_msg})
|
| 14 |
-
messages.append({"role": "assistant", "content": bot_msg})
|
| 15 |
-
|
| 16 |
-
messages.append({"role": "user", "content": message})
|
| 17 |
|
| 18 |
response = ""
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
except StopIteration:
|
| 28 |
-
pass # not strictly needed, but included for clarity
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
chatbot = gr.ChatInterface(fn=respond, chatbot=gr.Chatbot(), title="Mean Chatbot")
|
| 36 |
|
| 37 |
-
chatbot.launch(
|
| 38 |
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import random
|
| 4 |
|
| 5 |
+
client = InferenceClient("google/gemma-3-27b-it")
|
| 6 |
+
#this is where you change the LLM
|
| 7 |
+
|
| 8 |
+
def respond(message,history):
|
| 9 |
+
messages = [{"role": "system", "content": "You are a mean chatbot."}]
|
| 10 |
+
|
| 11 |
+
if history:
|
| 12 |
+
messages.extend(history)
|
| 13 |
|
| 14 |
+
message.append({"role": "user", "content": message})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
response = ""
|
| 17 |
|
| 18 |
+
for message in client.chat_completion(messages,max_tokens=50, stream=True):
|
| 19 |
+
token = message.choices[0].delta.content
|
| 20 |
+
response += token
|
| 21 |
+
yield response
|
| 22 |
+
|
| 23 |
+
#temperature=.9,
|
| 24 |
+
#top_p=.7) #changes the length of message
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
def echo(message, history):
|
| 27 |
+
choices = ["so true", "shut up", "you need help", "ts pmo sybau"] #change personality
|
| 28 |
+
#use random to select choices
|
| 29 |
+
chat_answer = random.choice(choices)
|
| 30 |
+
return chat_answer
|
| 31 |
|
| 32 |
+
chatbot = gr.ChatInterface(respond, type = "messages")
|
|
|
|
| 33 |
|
| 34 |
+
chatbot.launch()
|
| 35 |
|
| 36 |
+
chatbot.launch(debug=True)
|