Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
models = ["gpt2", "microsoft/phi-2","meta-llama/Llama-2-7b-chat-hf" ]
|
5 |
+
|
6 |
+
def generate_text(prompt, model, max_length, temperature):
|
7 |
+
pipe = pipeline("text-generation", model=model,trust_remote_code = True)
|
8 |
+
try:
|
9 |
+
generated_text = pipe(prompt, max_length=max_length, temperature=temperature)[0]["generated_text"]
|
10 |
+
return generated_text
|
11 |
+
except Exception as e:
|
12 |
+
return f"An error occurred: {str(e)}"
|
13 |
+
|
14 |
+
gr.Interface(
|
15 |
+
generate_text,
|
16 |
+
[
|
17 |
+
gr.Textbox(label="Enter your Prompt"),
|
18 |
+
gr.Dropdown(models, label="choose your Model" ),
|
19 |
+
gr.Slider(minimum=50, maximum=650, step=50),
|
20 |
+
gr.Slider(minimum=0.1, maximum=1, step=0.1),
|
21 |
+
],
|
22 |
+
outputs="text"
|
23 |
+
).launch()
|