Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,36 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
def
|
| 12 |
try:
|
| 13 |
response = model(
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
temperature=0.
|
| 17 |
-
|
| 18 |
)
|
| 19 |
-
return response[0]['generated_text']
|
| 20 |
except Exception as e:
|
| 21 |
return f"Error: {str(e)}"
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Minimal stable configuration
|
| 5 |
+
def load_model():
|
| 6 |
+
return pipeline(
|
| 7 |
+
"text-generation",
|
| 8 |
+
model="distilgpt2", # Smallest reliable model
|
| 9 |
+
device="cpu",
|
| 10 |
+
framework="pt"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
model = load_model()
|
| 14 |
|
| 15 |
+
def generate_text(prompt):
|
| 16 |
try:
|
| 17 |
response = model(
|
| 18 |
+
prompt,
|
| 19 |
+
max_length=50,
|
| 20 |
+
temperature=0.7,
|
| 21 |
+
num_return_sequences=1
|
| 22 |
)
|
| 23 |
+
return response[0]['generated_text']
|
| 24 |
except Exception as e:
|
| 25 |
return f"Error: {str(e)}"
|
| 26 |
|
| 27 |
+
# Basic interface
|
| 28 |
+
iface = gr.Interface(
|
| 29 |
+
fn=generate_text,
|
| 30 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your prompt..."),
|
| 31 |
+
outputs=gr.Textbox(),
|
| 32 |
+
title="Stable Text Generator",
|
| 33 |
+
description="Basic but guaranteed-to-work version"
|
| 34 |
)
|
| 35 |
|
| 36 |
+
iface.launch(server_name="0.0.0.0")
|