Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,47 +2,37 @@ import os
|
|
2 |
import requests
|
3 |
import gradio as gr
|
4 |
from dotenv import load_dotenv
|
5 |
-
from transformers import AutoTokenizer
|
6 |
|
7 |
load_dotenv()
|
8 |
|
9 |
-
|
10 |
-
|
|
|
11 |
|
12 |
-
API_URL = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct"
|
13 |
headers = {"Authorization": f"Bearer {os.getenv('HF_API_KEY')}"}
|
14 |
|
15 |
-
def
|
16 |
-
|
17 |
-
return prompt
|
18 |
-
|
19 |
-
def query(payload):
|
20 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
21 |
return response.json()
|
22 |
-
|
23 |
-
def respond(message
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
generated_text = response[0]['generated_text']
|
34 |
-
assistant_message = generated_text.split("Assistant:")[-1]
|
35 |
-
assistant_message = assistant_message.split("User:")[0].strip() # Only keep the text before the first "User:"
|
36 |
-
return assistant_message
|
37 |
|
38 |
iface = gr.Interface(
|
39 |
respond,
|
40 |
-
inputs=
|
41 |
-
gr.inputs.Textbox(label="Your question"),
|
42 |
-
gr.inputs.Textbox(label="System message", lines=2, default="A conversation between a user and an AI assistant. The assistant gives helpful and honest answers.")
|
43 |
-
],
|
44 |
outputs=[
|
45 |
-
gr.outputs.Textbox(label="
|
|
|
|
|
46 |
],
|
47 |
)
|
48 |
|
|
|
2 |
import requests
|
3 |
import gradio as gr
|
4 |
from dotenv import load_dotenv
|
|
|
5 |
|
6 |
load_dotenv()
|
7 |
|
8 |
+
API_URL_FALCON = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct"
|
9 |
+
API_URL_GUANACO = "https://api-inference.huggingface.co/models/timdettmers/guanaco-33b-merged"
|
10 |
+
API_URL_PYTHIA = "https://api-inference.huggingface.co/models/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5"
|
11 |
|
|
|
12 |
headers = {"Authorization": f"Bearer {os.getenv('HF_API_KEY')}"}
|
13 |
|
14 |
+
def query(api_url, payload):
|
15 |
+
response = requests.post(api_url, headers=headers, json=payload)
|
|
|
|
|
|
|
|
|
16 |
return response.json()
|
17 |
+
|
18 |
+
def respond(message):
|
19 |
+
response_falcon = query(API_URL_FALCON, {"inputs": message})
|
20 |
+
response_guanaco = query(API_URL_GUANACO, {"inputs": message})
|
21 |
+
response_pythia = query(API_URL_PYTHIA, {"inputs": message})
|
22 |
+
|
23 |
+
generated_text_falcon = response_falcon[0]['generated_text']
|
24 |
+
generated_text_guanaco = response_guanaco[0]['generated_text']
|
25 |
+
generated_text_pythia = response_pythia[0]['generated_text']
|
26 |
+
|
27 |
+
return generated_text_falcon, generated_text_guanaco, generated_text_pythia
|
|
|
|
|
|
|
|
|
28 |
|
29 |
iface = gr.Interface(
|
30 |
respond,
|
31 |
+
inputs=gr.inputs.Textbox(label="Prompt"),
|
|
|
|
|
|
|
32 |
outputs=[
|
33 |
+
gr.outputs.Textbox(label="Falcon Response"),
|
34 |
+
gr.outputs.Textbox(label="Guanaco Response"),
|
35 |
+
gr.outputs.Textbox(label="Pythia Response")
|
36 |
],
|
37 |
)
|
38 |
|