Upload Gen AI.py
Browse files
Gen AI.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline, set_seed
|
3 |
+
|
4 |
+
generator = pipeline('text-generation', model='flax-community/miniLM-L6-h384-uncased', device=0)
|
5 |
+
|
6 |
+
def generate_text(prompt, length=50, temperature=0.7, seed=42):
|
7 |
+
set_seed(seed)
|
8 |
+
output = generator(prompt, max_length=length, do_sample=True, temperature=temperature)
|
9 |
+
return output[0]['generated_text']
|
10 |
+
|
11 |
+
inputs = gr.inputs.Textbox(lines=5, label="Prompt")
|
12 |
+
outputs = gr.outputs.Textbox(label="Output Text")
|
13 |
+
temperature_slider = gr.inputs.Slider(minimum=0.1, maximum=1.5, default=0.7, label="Temperature")
|
14 |
+
length_slider = gr.inputs.Slider(minimum=10, maximum=200, default=50, label="Length")
|
15 |
+
seed_input = gr.inputs.Number(default=42, label="Seed")
|
16 |
+
|
17 |
+
gr.Interface(fn=generate_text, inputs=[inputs, length_slider, temperature_slider, seed_input], outputs=outputs, title="Generative AI", description="Use MiniLM to generate text based on a prompt.").launch()
|