aifeifei798 commited on
Commit
709118c
·
verified ·
1 Parent(s): c78055d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -4
app.py CHANGED
@@ -1,13 +1,37 @@
1
  import gradio as gr
 
 
 
 
 
 
2
 
3
  def echo(message, history):
4
- return message["text"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  demo = gr.ChatInterface(
7
  fn=echo,
8
  type="messages",
9
- examples=[{"text": "hello"}, {"text": "hola"}, {"text": "merhaba"}],
10
- title="Echo Bot",
11
- multimodal=True,
12
  )
13
  demo.launch()
 
1
  import gradio as gr
2
+ from openai import OpenAI
3
+
4
+ client = OpenAI(
5
+ base_url="https://api-inference.huggingface.co/v1/",
6
+ api_key=os.getenv('user_api')
7
+ )
8
 
9
  def echo(message, history):
10
+
11
+ messages = [
12
+ { "role": "user", "content": "hi" },
13
+ { "role": "assistant", "content": "Hello! How can I assist you today? If you have any questions or just want to chat, feel free! 😊" },
14
+ { "role": "user", "content": "" }
15
+ ]
16
+
17
+ stream = client.chat.completions.create(
18
+ model="mistralai/Mistral-Nemo-Instruct-2407",
19
+ messages=messages,
20
+ temperature=0.5,
21
+ max_tokens=1024,
22
+ top_p=0.7,
23
+ stream=True
24
+ )
25
+
26
+ for chunk in stream:
27
+ if chunk.choices[0].delta.content is not None:
28
+ temp += chunk.choices[0].delta.content
29
+ yield temp
30
 
31
  demo = gr.ChatInterface(
32
  fn=echo,
33
  type="messages",
34
+ title="FeiFei-Chat",
35
+ multimodal=False,
 
36
  )
37
  demo.launch()