File size: 1,107 Bytes
118fce7
 
c4bbf27
118fce7
 
c4bbf27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118fce7
 
 
 
 
 
 
 
 
 
 
c4bbf27
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
import gradio as gr
from generate import generate_text
import torch

def generate(prompt):
    try:
        # Redirect print output to capture the generated text
        import io
        import sys
        old_stdout = sys.stdout
        new_stdout = io.StringIO()
        sys.stdout = new_stdout
        
        # Generate text with default parameters
        generate_text(
            prompt=prompt,
            max_length=100,  # default value
            num_sequences=5  # default value
        )
        
        # Get the output and restore stdout
        output = new_stdout.getvalue()
        sys.stdout = old_stdout
        
        return output
    except Exception as e:
        return f"An error occurred: {str(e)}"

# Create the Gradio interface
demo = gr.Interface(
    fn=generate,
    inputs=gr.Textbox(label="Enter your prompt", lines=3),
    outputs=gr.Textbox(label="Generated Text", lines=10),
    title="Text Generation Demo",
    description="Enter a prompt and get generated text responses.",
)

if __name__ == "__main__":
    demo.launch()