Spaces:
Sleeping
Sleeping
File size: 2,048 Bytes
0096596 a98c10e 0096596 a98c10e 0096596 a98c10e 8d61d6f 0096596 8d61d6f 32615be a98c10e 32615be 0096596 b8feee6 a98c10e 0096596 0e1f78e 0096596 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import gradio as gr
import requests
import json
def call_api(prompt, history_json, system_prompt, temperature, max_new_tokens, top_p, repetition_penalty):
url = "https://seawolf2357-nvidia-llama-fastapi.hf.space/generate/"
try:
# JSON ํํ์ history๋ฅผ ํ์ฑ ์๋
history = json.loads(history_json)
except json.JSONDecodeError:
return "History input must be valid JSON. E.g., [[\"User\", \"Bot response\"], [\"User2\", \"Response2\"]]"
data = {
"prompt": prompt,
"history": history,
"system_prompt": system_prompt,
"temperature": temperature,
"max_new_tokens": max_new_tokens,
"top_p": top_p,
"repetition_penalty": repetition_penalty
}
try:
response = requests.post(url, json=data)
response.raise_for_status() # Raises HTTPError for bad requests
return response.json()['response']
except requests.exceptions.RequestException as e:
return f"An error occurred: {str(e)}"
def main_interface():
with gr.Blocks() as demo:
with gr.Row():
prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
history = gr.TextArea(label="History", placeholder="Enter history as JSON array...", lines=3)
system_prompt = gr.Textbox(label="System Prompt", placeholder="๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ๋ผ")
temperature = gr.Number(label="Temperature", value=0.3)
max_new_tokens = gr.Number(label="Max New Tokens", value=1048)
top_p = gr.Number(label="Top P", value=0.95)
repetition_penalty = gr.Number(label="Repetition Penalty", value=1.0)
submit_button = gr.Button("Generate")
submit_button.click(
fn=call_api,
inputs=[prompt, history, system_prompt, temperature, max_new_tokens, top_p, repetition_penalty],
outputs=[gr.Textbox(label="Response")]
)
return demo
if __name__ == "__main__":
demo = main_interface()
demo.launch()
|