dextersud's picture
Update app.py
e696b7d verified
import requests
import gradio as gr
def generate_prompt(instruction):
# Define the prompt format with the instruction
prompt = f"###Instruction:\n{instruction}\n\n###Response\n:"
return prompt
def my_model(instruction):
public_url = "https://0577-35-193-135-91.ngrok-free.app/generate"
# Generate the prompt from the instruction
prompt = generate_prompt(instruction)
# Correct JSON format
payload = {
"prompt": prompt
}
response = requests.post(public_url, json=payload)
# Check for valid JSON response
try:
result = response.json()
return result.get('generated_text', 'No text generated')
except ValueError:
return 'Failed to decode JSON from response'
# Define the Gradio interface
def create_interface():
with gr.Blocks() as demo:
gr.Markdown("# Text Generation with Your Model")
gr.Markdown("Enter an instruction below and get the generated text from the model.")
with gr.Row():
instruction_input = gr.Textbox(
label="Instruction",
placeholder="Enter your instruction here...",
lines=3,
max_lines=3
)
submit_button = gr.Button("Generate")
output_text = gr.Textbox(
label="Generated Text",
lines=10,
placeholder="Generated text will appear here...",
max_lines=10
)
submit_button.click(fn=my_model, inputs=instruction_input, outputs=output_text)
return demo
if __name__ == "__main__":
# Launch the Gradio app
create_interface().launch()