sathwikabhavaraju2005 commited on
Commit
7209ab6
·
verified ·
1 Parent(s): 9217968

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -15,26 +15,30 @@ headers = {"Authorization": f"Bearer {HF_TOKEN}"}
15
  # ----------------- FEATURE FUNCTIONS -----------------
16
 
17
  def generate_quiz(text, num_questions):
18
- prompt = f"Generate {num_questions} multiple choice questions from the following content:\n\n{text}\n\nInclude options A, B, C, D and correct answer."
 
 
 
 
19
 
20
  API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-small"
21
  payload = {
22
  "inputs": prompt,
23
- "parameters": {
24
- "temperature": 0.7,
25
- "max_new_tokens": 300
26
- }
27
  }
28
 
29
  response = requests.post(API_URL, headers=headers, json=payload)
 
30
  try:
31
  result = response.json()
32
  if isinstance(result, list) and "generated_text" in result[0]:
33
- return result[0]["generated_text"]
 
34
  else:
35
- return "⚠️ Model returned no valid output. Try changing the input or reduce question count."
36
  except Exception as e:
37
- return f"⚠️ API Error: {str(e)}"
 
38
 
39
 
40
 
 
15
  # ----------------- FEATURE FUNCTIONS -----------------
16
 
17
  def generate_quiz(text, num_questions):
18
+ prompt = (
19
+ f"Generate {num_questions} simple quiz questions from the following text:\n\n"
20
+ f"{text}\n\n"
21
+ f"Each question should be followed by options A, B, C, D and a correct answer."
22
+ )
23
 
24
  API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-small"
25
  payload = {
26
  "inputs": prompt,
27
+ "parameters": {"max_new_tokens": 300}
 
 
 
28
  }
29
 
30
  response = requests.post(API_URL, headers=headers, json=payload)
31
+
32
  try:
33
  result = response.json()
34
  if isinstance(result, list) and "generated_text" in result[0]:
35
+ output = result[0]["generated_text"].strip()
36
+ return output if output else "⚠️ Model returned empty text. Try reducing question count or using a smaller paragraph."
37
  else:
38
+ return f"⚠️ Model didn't return expected output. Try fewer questions or simpler content."
39
  except Exception as e:
40
+ return f"⚠️ API Error: {e}"
41
+
42
 
43
 
44