Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
# Create the Gradio interface
|
| 16 |
iface = gr.Interface(
|
| 17 |
-
fn=
|
| 18 |
-
inputs=gr.Textbox(label="Enter your prompt
|
| 19 |
-
outputs=gr.Textbox(label="Model Response
|
| 20 |
-
title="
|
| 21 |
-
description="Enter a
|
| 22 |
)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load a text generation pipeline from a Hugging Face model
|
| 5 |
+
# You can replace this model with "meta-llama/Llama-2-7b-chat-hf" or "mistralai/Mistral-7B-Instruct" if available and compatible
|
| 6 |
+
generator = pipeline("text-generation", model="meta-llama/Llama-2-7b-chat-hf")
|
| 7 |
|
| 8 |
+
def evaluate_response(prompt):
|
| 9 |
+
# Generate text from the prompt
|
| 10 |
+
outputs = generator(prompt, max_new_tokens=150, do_sample=True, temperature=0.7)
|
| 11 |
+
generated_text = outputs[0]['generated_text']
|
| 12 |
+
|
| 13 |
+
# Simple quality evaluation: check length of generated response
|
| 14 |
+
word_count = len(generated_text.split())
|
| 15 |
+
quality = "Good" if word_count > 10 else "Poor"
|
| 16 |
+
|
| 17 |
+
return generated_text, f"Response Quality: {quality}"
|
| 18 |
|
|
|
|
| 19 |
iface = gr.Interface(
|
| 20 |
+
fn=evaluate_response,
|
| 21 |
+
inputs=gr.Textbox(lines=4, label="Enter your prompt"),
|
| 22 |
+
outputs=[gr.Textbox(label="Model Response"), gr.Textbox(label="Quality Analysis")],
|
| 23 |
+
title="Model Understanding Test",
|
| 24 |
+
description="Enter instructions or a question, the app sends it to a language model and evaluates the response quality."
|
| 25 |
)
|
| 26 |
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
iface.launch()
|