rrk757 commited on
Commit
f9d2275
·
verified ·
1 Parent(s): b00fdfe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -26
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-1.1-7b-it") # Use a smaller model for smoother results
6
-
7
- def respond(message, history):
8
- messages = [{"role": "system", "content": "You are a mean chatbot."}]
 
 
 
 
9
 
10
- # Convert chat history to messages
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
- try:
21
- for chunk in client.chat_completion(messages, max_tokens=100, stream=True):
22
- if chunk.choices and chunk.choices[0].delta:
23
- token = chunk.choices[0].delta.get("content", "")
24
- response += token
25
- yield response # streaming response
26
-
27
- except StopIteration:
28
- pass # not strictly needed, but included for clarity
29
 
30
- # Final yield to make sure a value is returned
31
- if not response:
32
- yield "..."
 
 
33
 
34
- # Set up the Gradio interface
35
- chatbot = gr.ChatInterface(fn=respond, chatbot=gr.Chatbot(), title="Mean Chatbot")
36
 
37
- chatbot.launch(debug=True)
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)