Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ from transformers import pipeline
|
|
| 13 |
stt = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
| 14 |
|
| 15 |
# Better Tutor Model (FLAN-T5)
|
| 16 |
-
llm = pipeline("
|
| 17 |
|
| 18 |
|
| 19 |
# -------------------------------
|
|
@@ -37,26 +37,22 @@ def speech_to_text(audio):
|
|
| 37 |
|
| 38 |
|
| 39 |
def generate_response(text):
|
| 40 |
-
"""
|
| 41 |
-
Generates tutor-style response
|
| 42 |
-
"""
|
| 43 |
if not text or text == "No audio provided.":
|
| 44 |
return "Please provide valid input."
|
| 45 |
|
| 46 |
prompt = f"""
|
| 47 |
-
You are an
|
| 48 |
-
|
| 49 |
-
Explain:
|
| 50 |
-
- in simple words
|
| 51 |
-
- step by step
|
| 52 |
-
- with examples if possible
|
| 53 |
|
| 54 |
Question: {text}
|
| 55 |
Answer:
|
| 56 |
"""
|
| 57 |
|
| 58 |
-
output = llm(prompt, max_length=150)
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
|
| 62 |
# -------------------------------
|
|
|
|
| 13 |
stt = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
| 14 |
|
| 15 |
# Better Tutor Model (FLAN-T5)
|
| 16 |
+
llm = pipeline("text-generation", model="distilgpt2")
|
| 17 |
|
| 18 |
|
| 19 |
# -------------------------------
|
|
|
|
| 37 |
|
| 38 |
|
| 39 |
def generate_response(text):
|
|
|
|
|
|
|
|
|
|
| 40 |
if not text or text == "No audio provided.":
|
| 41 |
return "Please provide valid input."
|
| 42 |
|
| 43 |
prompt = f"""
|
| 44 |
+
You are an AI tutor.
|
| 45 |
+
Explain clearly and simply.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
Question: {text}
|
| 48 |
Answer:
|
| 49 |
"""
|
| 50 |
|
| 51 |
+
output = llm(prompt, max_length=150, num_return_sequences=1)
|
| 52 |
+
response = output[0]["generated_text"]
|
| 53 |
+
|
| 54 |
+
# Clean output
|
| 55 |
+
return response.split("Answer:")[-1].strip()
|
| 56 |
|
| 57 |
|
| 58 |
# -------------------------------
|