Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,16 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
model = pipeline("text-generation", model="
|
| 5 |
-
|
| 6 |
-
def evaluate(prompt, response):
|
| 7 |
-
prompt_lower = prompt.lower()
|
| 8 |
-
response_lower = response.lower()
|
| 9 |
-
keywords = [word for word in prompt_lower.split() if len(word) > 3]
|
| 10 |
-
matches = sum(1 for word in keywords if word in response_lower)
|
| 11 |
-
is_question = any(q in prompt_lower for q in ["who", "what", "when", "where", "why", "how"])
|
| 12 |
-
min_length = max(len(prompt)//2, 10)
|
| 13 |
-
|
| 14 |
-
if is_question:
|
| 15 |
-
understood = any(a in response_lower for a in ["answer", "is", "are", "because"])
|
| 16 |
-
else:
|
| 17 |
-
understood = matches >= len(keywords)//2
|
| 18 |
-
|
| 19 |
-
return understood and len(response) >= min_length
|
| 20 |
|
| 21 |
def process(prompt):
|
| 22 |
response = model(prompt, max_new_tokens=150)[0]['generated_text']
|
| 23 |
-
|
| 24 |
-
evaluation = "✔ Understood" if evaluate(prompt, response) else "❌ Didn't understand"
|
| 25 |
-
return f"{response}\n\nEvaluation: {evaluation}"
|
| 26 |
|
| 27 |
with gr.Blocks() as app:
|
| 28 |
-
gr.Markdown("# Model
|
| 29 |
-
inp = gr.Textbox(label="Enter Prompt"
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
btn.click(process, inputs=inp, outputs=out)
|
| 33 |
|
| 34 |
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
model = pipeline("text-generation", model="gpt2") # Smaller model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def process(prompt):
|
| 7 |
response = model(prompt, max_new_tokens=150)[0]['generated_text']
|
| 8 |
+
return response.replace(prompt, "").strip()
|
|
|
|
|
|
|
| 9 |
|
| 10 |
with gr.Blocks() as app:
|
| 11 |
+
gr.Markdown("# Model Tester")
|
| 12 |
+
inp = gr.Textbox(label="Enter Prompt")
|
| 13 |
+
out = gr.Textbox(label="Response")
|
| 14 |
+
inp.change(process, inp, out)
|
|
|
|
| 15 |
|
| 16 |
app.launch()
|