Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,30 @@
|
|
| 1 |
-
# Example: Gradio app for Zephyr-7B
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import pipeline
|
|
|
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import time
|
| 4 |
|
| 5 |
+
# Initialize model (replace with your actual setup)
|
| 6 |
+
model = pipeline("text-generation", model="gpt2")
|
| 7 |
|
| 8 |
+
def respond(prompt):
|
| 9 |
+
if not prompt.strip():
|
| 10 |
+
return "Please enter a message"
|
| 11 |
+
|
| 12 |
+
print(f"Processing: {prompt}") # Debug log
|
| 13 |
+
start_time = time.time()
|
| 14 |
+
|
| 15 |
+
try:
|
| 16 |
+
response = model(prompt, max_length=50)[0]['generated_text']
|
| 17 |
+
print(f"Response: {response}") # Debug log
|
| 18 |
+
return response
|
| 19 |
+
except Exception as e:
|
| 20 |
+
print(f"Error: {str(e)}")
|
| 21 |
+
return f"Error: {str(e)}"
|
| 22 |
|
| 23 |
+
# Launch interface
|
| 24 |
+
gr.Interface(
|
| 25 |
+
fn=respond,
|
| 26 |
+
inputs="textbox",
|
| 27 |
+
outputs="textbox",
|
| 28 |
+
title="My AI Assistant",
|
| 29 |
+
description="Type something and press Enter"
|
| 30 |
+
).launch()
|