annakcarls commited on
Commit
da57d79
·
verified ·
1 Parent(s): ec8cb7d

changing to generative AI token

Browse files
Files changed (1) hide show
  1. app.py +19 -32
app.py CHANGED
@@ -1,38 +1,25 @@
1
  import gradio as gr
2
- import random
3
 
4
- def magic_8_ball(message, history):
5
- responses = [
6
- "Without a doubt.",
7
- "Outlook not so good.",
8
- "Ask again later.",
9
- "Yes, definitely!",
10
- "My sources say no.",
11
- "Signs point to yes.",
12
- "Don't count on it.",
13
- "It is certain.",
14
- "Better not tell you now.",
15
- "Very doubtful.",
16
- "Reply hazy, try again.",
17
- "You may rely on it.",
18
- "Concentrate and ask again.",
19
- "My reply is no.",
20
- "As I see it, yes.",
21
- "Most likely.",
22
- "Yes.",
23
- "No.",
24
- "Cannot predict now.",
25
- "It is decidedly so."
26
- ]
27
- response = random.choice(responses)
28
- return response
29
 
30
- chatbot = gr.ChatInterface(
31
- magic_8_ball,
32
- type="messages",
33
- title="Magic 8 Ball Chatbot",
34
- description="Ask any yes–no question and let the Magic 8 Ball reveal your fate!"
35
- )
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  chatbot.launch()
38
 
 
1
  import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
 
4
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ def respond(message, history):
7
+
8
+ messages = [{"role": "system", "content": "You are a friendly chatbot."}]
9
+
10
+ if history:
11
+ messages.extend(history)
12
+
13
+ messages.append({"role": "user", "content": message})
14
+
15
+ response = client.chat_completion(
16
+ messages,
17
+ max_tokens=100
18
+ )
19
+
20
+ return response['choices'][0]['message']['content'].strip()
21
+
22
+ chatbot = gr.ChatInterface(respond, type="messages")
23
 
24
  chatbot.launch()
25