Spaces:
Running
Running
fix 12
Browse files
app.py
CHANGED
@@ -11,20 +11,6 @@ huggingface_token = os.getenv("SECRET_ENV_VARIABLE")
|
|
11 |
#client = InferenceClient(api_key=huggingface_token)
|
12 |
client = InferenceClient(model=model_name, token=huggingface_token)
|
13 |
|
14 |
-
'''
|
15 |
-
import requests
|
16 |
-
|
17 |
-
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-3.2-1B"
|
18 |
-
headers = {"Authorization": "Bearer "}
|
19 |
-
|
20 |
-
def query(payload):
|
21 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
22 |
-
return response.json()
|
23 |
-
|
24 |
-
output = query({
|
25 |
-
"inputs": "Can you please let us know more details about your ",
|
26 |
-
})
|
27 |
-
'''
|
28 |
|
29 |
def generate_text(
|
30 |
prompt,
|
@@ -53,60 +39,6 @@ def generate_text(
|
|
53 |
|
54 |
|
55 |
|
56 |
-
def respond(
|
57 |
-
message,
|
58 |
-
history: list[tuple[str, str]],
|
59 |
-
system_message,
|
60 |
-
max_tokens,
|
61 |
-
temperature,
|
62 |
-
top_p,
|
63 |
-
):
|
64 |
-
messages = [{"role": "system", "content": system_message}]
|
65 |
-
|
66 |
-
for val in history:
|
67 |
-
if val[0]:
|
68 |
-
messages.append({"role": "user", "content": val[0]})
|
69 |
-
if val[1]:
|
70 |
-
messages.append({"role": "assistant", "content": val[1]})
|
71 |
-
|
72 |
-
messages.append({"role": "user", "content": message})
|
73 |
-
|
74 |
-
response = ""
|
75 |
-
|
76 |
-
for message in client.chat_completion(
|
77 |
-
messages,
|
78 |
-
max_tokens=max_tokens,
|
79 |
-
stream=True,
|
80 |
-
temperature=temperature,
|
81 |
-
top_p=top_p,
|
82 |
-
):
|
83 |
-
token = message.choices[0].delta.content
|
84 |
-
|
85 |
-
response += token
|
86 |
-
yield response
|
87 |
-
|
88 |
-
|
89 |
-
"""
|
90 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
91 |
-
|
92 |
-
demo = gr.ChatInterface(
|
93 |
-
#respond,
|
94 |
-
generate_text,
|
95 |
-
additional_inputs=[
|
96 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
97 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
98 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
99 |
-
gr.Slider(
|
100 |
-
minimum=0.1,
|
101 |
-
maximum=1.0,
|
102 |
-
value=0.95,
|
103 |
-
step=0.05,
|
104 |
-
label="Top-p (nucleus sampling)",
|
105 |
-
),
|
106 |
-
],
|
107 |
-
)
|
108 |
-
"""
|
109 |
-
|
110 |
with gr.Blocks() as demo:
|
111 |
gr.Markdown("Q&A App")
|
112 |
|
|
|
11 |
#client = InferenceClient(api_key=huggingface_token)
|
12 |
client = InferenceClient(model=model_name, token=huggingface_token)
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
def generate_text(
|
16 |
prompt,
|
|
|
39 |
|
40 |
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
with gr.Blocks() as demo:
|
43 |
gr.Markdown("Q&A App")
|
44 |
|