Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
3 |
|
4 |
-
def call_api(prompt,
|
5 |
url = "https://seawolf2357-nvidia-llama-fastapi.hf.space/generate/"
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
data = {
|
7 |
"prompt": prompt,
|
8 |
"history": history,
|
@@ -12,23 +19,23 @@ def call_api(prompt, history, system_prompt, temperature, max_new_tokens, top_p,
|
|
12 |
"top_p": top_p,
|
13 |
"repetition_penalty": repetition_penalty
|
14 |
}
|
|
|
15 |
try:
|
16 |
response = requests.post(url, json=data)
|
17 |
-
response.raise_for_status() #
|
18 |
return response.json()['response']
|
19 |
except requests.exceptions.RequestException as e:
|
20 |
return f"An error occurred: {str(e)}"
|
21 |
|
22 |
-
|
23 |
def main_interface():
|
24 |
with gr.Blocks() as demo:
|
25 |
with gr.Row():
|
26 |
prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
|
27 |
-
history = gr.Textbox(label="History", placeholder="Enter history
|
28 |
-
system_prompt = gr.Textbox(label="System Prompt", placeholder="
|
29 |
-
temperature = gr.Number(label="Temperature", value=0.
|
30 |
max_new_tokens = gr.Number(label="Max New Tokens", value=1048)
|
31 |
-
top_p = gr.Number(label="Top P", value=0.
|
32 |
repetition_penalty = gr.Number(label="Repetition Penalty", value=1.0)
|
33 |
submit_button = gr.Button("Generate")
|
34 |
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
+
import json
|
4 |
|
5 |
+
def call_api(prompt, history_json, system_prompt, temperature, max_new_tokens, top_p, repetition_penalty):
|
6 |
url = "https://seawolf2357-nvidia-llama-fastapi.hf.space/generate/"
|
7 |
+
try:
|
8 |
+
# JSON ํํ์ history๋ฅผ ํ์ฑ ์๋
|
9 |
+
history = json.loads(history_json)
|
10 |
+
except json.JSONDecodeError:
|
11 |
+
return "History input must be valid JSON. E.g., [[\"User\", \"Bot response\"], [\"User2\", \"Response2\"]]"
|
12 |
+
|
13 |
data = {
|
14 |
"prompt": prompt,
|
15 |
"history": history,
|
|
|
19 |
"top_p": top_p,
|
20 |
"repetition_penalty": repetition_penalty
|
21 |
}
|
22 |
+
|
23 |
try:
|
24 |
response = requests.post(url, json=data)
|
25 |
+
response.raise_for_status() # Raises HTTPError for bad requests
|
26 |
return response.json()['response']
|
27 |
except requests.exceptions.RequestException as e:
|
28 |
return f"An error occurred: {str(e)}"
|
29 |
|
|
|
30 |
def main_interface():
|
31 |
with gr.Blocks() as demo:
|
32 |
with gr.Row():
|
33 |
prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
|
34 |
+
history = gr.Textbox(label="History", placeholder="Enter history as JSON array...", multiline=True)
|
35 |
+
system_prompt = gr.Textbox(label="System Prompt", placeholder="๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ๋ผ")
|
36 |
+
temperature = gr.Number(label="Temperature", value=0.3)
|
37 |
max_new_tokens = gr.Number(label="Max New Tokens", value=1048)
|
38 |
+
top_p = gr.Number(label="Top P", value=0.9)
|
39 |
repetition_penalty = gr.Number(label="Repetition Penalty", value=1.0)
|
40 |
submit_button = gr.Button("Generate")
|
41 |
|