File size: 1,698 Bytes
985abad
64a0ef2
96484e2
e696b7d
 
 
 
 
 
64a0ef2
 
e696b7d
 
 
64a0ef2
 
 
 
 
 
 
 
 
 
 
 
 
96484e2
64a0ef2
 
 
e696b7d
 
 
64a0ef2
e696b7d
 
 
 
 
 
64a0ef2
e696b7d
 
 
 
 
 
96484e2
e696b7d
96484e2
64a0ef2
96484e2
64a0ef2
 
e696b7d
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
54
55
56
57
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()