Spaces:
Sleeping
Sleeping
File size: 1,791 Bytes
0096596 32615be 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 |
import gradio as gr
import requests
def call_api(prompt, history, system_prompt, temperature, max_new_tokens, top_p, repetition_penalty):
url = "https://seawolf2357-nvidia-llama-fastapi.hf.space/generate/"
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() # μ΄ λΆλΆμμ HTTP μ€λ₯ λ°μ μ μμΈλ₯Ό λ°μμν΅λλ€.
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.Textbox(label="History", placeholder="Enter history here...")
system_prompt = gr.Textbox(label="System Prompt", placeholder="Enter system prompt here...")
temperature = gr.Number(label="Temperature", value=0.0)
max_new_tokens = gr.Number(label="Max New Tokens", value=1048)
top_p = gr.Number(label="Top P", value=0.15)
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()
|