Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
response
|
| 10 |
-
generated_text
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
quality = "Good" if word_count > 10 else "Poor"
|
| 15 |
-
|
| 16 |
-
return generated_text, f"Response Quality: {quality}"
|
| 17 |
|
| 18 |
-
#
|
| 19 |
iface = gr.Interface(
|
| 20 |
-
fn=
|
| 21 |
-
inputs=gr.Textbox(
|
| 22 |
-
outputs=
|
| 23 |
-
title="
|
| 24 |
-
description="Enter
|
| 25 |
)
|
| 26 |
|
|
|
|
| 27 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the model
|
| 5 |
+
model = pipeline("text-generation", model="meta-llama/Llama-2-7b-chat-hf")
|
| 6 |
|
| 7 |
+
def generate_response(prompt):
|
| 8 |
+
response = model(prompt, max_length=100, num_return_sequences=1)
|
| 9 |
+
# Check if the response is not empty and contains the expected key
|
| 10 |
+
if response and isinstance(response, list) and 'generated_text' in response[0]:
|
| 11 |
+
return response[0]['generated_text']
|
| 12 |
+
else:
|
| 13 |
+
return "Error: No response generated."
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
# Create the Gradio interface
|
| 16 |
iface = gr.Interface(
|
| 17 |
+
fn=generate_response,
|
| 18 |
+
inputs=gr.Textbox(label="Enter your prompt or question:"),
|
| 19 |
+
outputs=gr.Textbox(label="Model Response:"),
|
| 20 |
+
title="Test Understanding Prompt",
|
| 21 |
+
description="Enter a prompt to see how well the model understands it."
|
| 22 |
)
|
| 23 |
|
| 24 |
+
# Launch the app
|
| 25 |
iface.launch()
|