iseesaw commited on
Commit
232416e
1 Parent(s): 93e8300

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from openai import OpenAI
3
+ import gradio as gr
4
+
5
+ api_key = "token-abc123" # Replace with your key
6
+ base_url = "http://localhost:8000/v1"
7
+ client = OpenAI(api_key=api_key, base_url=base_url)
8
+
9
+ def predict(message, history):
10
+ history_openai_format = []
11
+ for human, assistant in history:
12
+ history_openai_format.append({"role": "user", "content": human })
13
+ history_openai_format.append({"role": "assistant", "content":assistant})
14
+ history_openai_format.append({"role": "user", "content": message})
15
+
16
+ response = client.chat.completions.create(model='Llama-3-8B-UltraMedical',
17
+ messages= history_openai_format,
18
+ temperature=1.0,
19
+ stop=["<|eot_id|>"],
20
+ stream=True)
21
+
22
+ partial_message = ""
23
+ for chunk in response:
24
+ if chunk.choices[0].delta.content is not None:
25
+ partial_message = partial_message + chunk.choices[0].delta.content
26
+ yield partial_message
27
+
28
+ gr.ChatInterface(predict).launch()
29
+