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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -15,17 +15,27 @@ headers = {"Authorization": f"Bearer {HF_TOKEN}"}
15
  # ----------------- FEATURE FUNCTIONS -----------------
16
 
17
  def generate_quiz(text, num_questions):
18
- prompt = f"Generate {num_questions} MCQ questions from this content:\n{text}"
 
19
  API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-small"
20
  payload = {
21
  "inputs": prompt,
22
- "parameters": {"max_new_tokens": 256}
 
 
 
23
  }
 
24
  response = requests.post(API_URL, headers=headers, json=payload)
25
  try:
26
- return response.json()[0]["generated_text"]
 
 
 
 
27
  except Exception as e:
28
- return f"⚠️ Error: {e}"
 
29
 
30
 
31
  def get_bot_response(query):
 
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
 
41
  def get_bot_response(query):