File size: 565 Bytes
d029233
e64eeea
41c07d1
 
d029233
e64eeea
d029233
e64eeea
99a11ed
 
 
 
 
d029233
9576a6b
99a11ed
41c07d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import gradio as gr
from transformers import pipeline
import torch
import numpy as np

generator = pipeline('text-generation', model='sshleifer/tiny-gpt2')

def generate_text(prompt):
    try:
        result = generator(prompt, max_length=50, num_return_sequences=1)
        return result[0]['generated_text']
    except Exception as e:
        return f"Error: {str(e)}"

if __name__ == "__main__":
    interface = gr.Interface(fn=generate_text, inputs="text", outputs="text", title="AI Code Generator")
    interface.launch(share=True)  # This line makes it public