Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +49 -0
- requirements.txt +73 -0
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
import gradio as gr
|
5 |
+
import time
|
6 |
+
|
7 |
+
# Define the function to make the API request
|
8 |
+
def fetch_response(messages, api_key):
|
9 |
+
start_time = time.time()
|
10 |
+
url = "https://api.fireworks.ai/inference/v1/chat/completions"
|
11 |
+
payload = {
|
12 |
+
"model": "accounts/fireworks/models/qwen2-72b-instruct",
|
13 |
+
"max_tokens": 4096,
|
14 |
+
"top_p": 1,
|
15 |
+
"top_k": 40,
|
16 |
+
"presence_penalty": 0,
|
17 |
+
"frequency_penalty": 0,
|
18 |
+
"temperature": 0.6,
|
19 |
+
"messages": [{"role": "user", "content": messages}]
|
20 |
+
}
|
21 |
+
headers = {
|
22 |
+
"Accept": "application/json",
|
23 |
+
"Content-Type": "application/json",
|
24 |
+
"Authorization": f"Bearer {api_key}"
|
25 |
+
}
|
26 |
+
response = requests.post(url, headers=headers, data=json.dumps(payload))
|
27 |
+
end_time = time.time()
|
28 |
+
response_json = response.json()
|
29 |
+
answer_time = end_time - start_time
|
30 |
+
return response_json['choices'][0]['message']['content'], answer_time
|
31 |
+
|
32 |
+
# Define the Gradio interface
|
33 |
+
def chatbot_interface(messages, api_key):
|
34 |
+
try:
|
35 |
+
answer, answer_time = fetch_response(messages, api_key)
|
36 |
+
return answer, f"<b><font color='blue'>Answer Time: {answer_time} seconds</font></b>"
|
37 |
+
except Exception as e:
|
38 |
+
return "Your API key is wrong. Try again!", None
|
39 |
+
|
40 |
+
# Create Gradio interface
|
41 |
+
iface = gr.Interface(fn=chatbot_interface,
|
42 |
+
inputs=[gr.Textbox(label="Message"), gr.Textbox(label="API Key", type="password")],
|
43 |
+
outputs=[gr.Textbox(label="Answer"), gr.Markdown(label="Answer Time")],
|
44 |
+
title="Qwen2 AI Chatbot - Test App - QWEN 2 is released 06.06.2024",
|
45 |
+
description="Feel free to chat with Qwen2 model from Alibaba. Please enter your API key.",
|
46 |
+
theme='Arkaine/Carl_Glow')
|
47 |
+
|
48 |
+
# Launch the interface
|
49 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
altair==5.3.0
|
3 |
+
annotated-types==0.7.0
|
4 |
+
anyio==4.4.0
|
5 |
+
attrs==23.2.0
|
6 |
+
certifi==2024.6.2
|
7 |
+
charset-normalizer==3.3.2
|
8 |
+
click==8.1.7
|
9 |
+
colorama==0.4.6
|
10 |
+
contourpy==1.2.1
|
11 |
+
cycler==0.12.1
|
12 |
+
dnspython==2.6.1
|
13 |
+
email_validator==2.1.1
|
14 |
+
exceptiongroup==1.2.1
|
15 |
+
fastapi==0.111.0
|
16 |
+
fastapi-cli==0.0.4
|
17 |
+
ffmpy==0.3.2
|
18 |
+
filelock==3.14.0
|
19 |
+
fonttools==4.53.0
|
20 |
+
fsspec==2024.6.0
|
21 |
+
gradio==4.36.0
|
22 |
+
gradio_client==1.0.1
|
23 |
+
h11==0.14.0
|
24 |
+
httpcore==1.0.5
|
25 |
+
httptools==0.6.1
|
26 |
+
httpx==0.27.0
|
27 |
+
huggingface-hub==0.23.3
|
28 |
+
idna==3.7
|
29 |
+
importlib_resources==6.4.0
|
30 |
+
Jinja2==3.1.4
|
31 |
+
jsonschema==4.22.0
|
32 |
+
jsonschema-specifications==2023.12.1
|
33 |
+
kiwisolver==1.4.5
|
34 |
+
markdown-it-py==3.0.0
|
35 |
+
MarkupSafe==2.1.5
|
36 |
+
matplotlib==3.9.0
|
37 |
+
mdurl==0.1.2
|
38 |
+
numpy==1.26.4
|
39 |
+
orjson==3.10.3
|
40 |
+
packaging==24.0
|
41 |
+
pandas==2.2.2
|
42 |
+
pillow==10.3.0
|
43 |
+
pydantic==2.7.3
|
44 |
+
pydantic_core==2.18.4
|
45 |
+
pydub==0.25.1
|
46 |
+
Pygments==2.18.0
|
47 |
+
pyparsing==3.1.2
|
48 |
+
python-dateutil==2.9.0.post0
|
49 |
+
python-dotenv==1.0.1
|
50 |
+
python-multipart==0.0.9
|
51 |
+
pytz==2024.1
|
52 |
+
PyYAML==6.0.1
|
53 |
+
referencing==0.35.1
|
54 |
+
requests==2.32.3
|
55 |
+
rich==13.7.1
|
56 |
+
rpds-py==0.18.1
|
57 |
+
ruff==0.4.8
|
58 |
+
semantic-version==2.10.0
|
59 |
+
shellingham==1.5.4
|
60 |
+
six==1.16.0
|
61 |
+
sniffio==1.3.1
|
62 |
+
starlette==0.37.2
|
63 |
+
tomlkit==0.12.0
|
64 |
+
toolz==0.12.1
|
65 |
+
tqdm==4.66.4
|
66 |
+
typer==0.12.3
|
67 |
+
typing_extensions==4.12.1
|
68 |
+
tzdata==2024.1
|
69 |
+
ujson==5.10.0
|
70 |
+
urllib3==2.2.1
|
71 |
+
uvicorn==0.30.1
|
72 |
+
watchfiles==0.22.0
|
73 |
+
websockets==11.0.3
|