Spaces:
Sleeping
Sleeping
initial commit
Browse files- app.py +25 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from friendli import Friendli
|
4 |
+
|
5 |
+
FRIENDLI_TOKEN = os.getenv("FRIENDLI_TOKEN")
|
6 |
+
client = Friendli(token=FRIENDLI_TOKEN)
|
7 |
+
|
8 |
+
def chat_function(message, history):
|
9 |
+
new_messages = []
|
10 |
+
for user, chatbot in history:
|
11 |
+
new_messages.append({"role" : "user", "content": user})
|
12 |
+
new_messages.append({"role" : "assistant", "content": chatbot})
|
13 |
+
new_messages.append({"role": "user", "content": message})
|
14 |
+
|
15 |
+
stream = client.chat.completions.create(
|
16 |
+
model="meta-llama-3-70b-instruct",
|
17 |
+
messages=new_messages,
|
18 |
+
stream=True
|
19 |
+
)
|
20 |
+
res = ""
|
21 |
+
for chunk in stream:
|
22 |
+
res += chunk.choices[0].delta.content or ""
|
23 |
+
yield res
|
24 |
+
|
25 |
+
gr.ChatInterface(chat_function).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
pip==24.0
|
2 |
+
friendli-client==1.3.4
|
3 |
+
gradio==4.26.0
|