sathwikabhavaraju2005 commited on
Commit
436047e
Β·
verified Β·
1 Parent(s): 8dcd06e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -31
app.py CHANGED
@@ -25,24 +25,24 @@ def analyze_weakness(csv_file):
25
  return summary.to_string()
26
 
27
  # ------------------------------
28
- # Teaching Assistant
29
  # ------------------------------
30
  def chatbot_response(message, history):
31
  return "This is a placeholder response for now. (LLM not integrated)"
32
 
33
  # ------------------------------
34
- # Speech Question Solver
35
  # ------------------------------
36
  def speech_answer(audio):
37
- return "Audio to text transcription + answer generation is not included in offline version."
38
 
39
  # ------------------------------
40
- # PDF/YT Summarizer
41
  # ------------------------------
42
  def summarize_text(text):
43
  input_text = f"summarize: {text.strip()}"
44
  input_ids = tokenizer_qg.encode(input_text, return_tensors="pt", max_length=512, truncation=True)
45
- summary_ids = model_qg.generate(input_ids, max_length=150, min_length=30, length_penalty=5., num_beams=2)
46
  return tokenizer_qg.decode(summary_ids[0], skip_special_tokens=True)
47
 
48
  # ------------------------------
@@ -50,18 +50,15 @@ def summarize_text(text):
50
  # ------------------------------
51
  def predict_engagement(file):
52
  df = pd.read_csv(file.name)
53
- avg_time = df['TimeSpent'].mean()
54
- if avg_time < 10:
55
- return "⚠️ Risk of disengagement"
56
- else:
57
- return "βœ… Engaged student"
58
 
59
  # ------------------------------
60
  # Badge Generator
61
  # ------------------------------
62
  def generate_badge(file):
63
  df = pd.read_csv(file.name)
64
- avg_score = df['Score'].mean()
65
  if avg_score >= 80:
66
  return "πŸ… Gold Badge"
67
  elif avg_score >= 50:
@@ -87,7 +84,7 @@ def check_plagiarism(text1, text2):
87
  return f"Similarity Score: {score:.2f} - {'⚠️ Possible Plagiarism' if score > 0.8 else 'βœ… Looks Original'}"
88
 
89
  # ------------------------------
90
- # Gradio UI
91
  # ------------------------------
92
  with gr.Blocks() as demo:
93
  gr.Markdown("# πŸ“š AI-Powered LMS Suite (Offline Mode)")
@@ -109,9 +106,9 @@ with gr.Blocks() as demo:
109
  gr.ChatInterface(fn=chatbot_response)
110
 
111
  with gr.Tab("🎀 Speech Q Solver"):
112
- audio_in = gr.Audio(source="microphone", type="filepath")
113
- audio_btn = gr.Button("Answer")
114
- audio_out = gr.Textbox()
115
  audio_btn.click(fn=speech_answer, inputs=audio_in, outputs=audio_out)
116
 
117
  with gr.Tab("πŸ“„ Summarizer"):
@@ -136,19 +133,4 @@ with gr.Blocks() as demo:
136
  trans_in = gr.Textbox(label="Enter Text")
137
  trans_lang = gr.Textbox(label="Target Language")
138
  trans_btn = gr.Button("Translate")
139
- trans_out = gr.Textbox()
140
- trans_btn.click(fn=translate_text, inputs=[trans_in, trans_lang], outputs=trans_out)
141
-
142
- with gr.Tab("πŸ“‹ Plagiarism Checker"):
143
- text1 = gr.Textbox(label="Text 1", lines=3)
144
- text2 = gr.Textbox(label="Text 2", lines=3)
145
- plag_btn = gr.Button("Check Similarity")
146
- plag_out = gr.Textbox()
147
- plag_btn.click(fn=check_plagiarism, inputs=[text1, text2], outputs=plag_out)
148
-
149
- # ------------------------------
150
- # Launch App
151
- # ------------------------------
152
- demo.launch()
153
-
154
-
 
25
  return summary.to_string()
26
 
27
  # ------------------------------
28
+ # Teaching Assistant (Placeholder)
29
  # ------------------------------
30
  def chatbot_response(message, history):
31
  return "This is a placeholder response for now. (LLM not integrated)"
32
 
33
  # ------------------------------
34
+ # Speech Question Solver (Mock)
35
  # ------------------------------
36
  def speech_answer(audio):
37
+ return "Audio transcription and answer generation not supported offline."
38
 
39
  # ------------------------------
40
+ # Summarizer
41
  # ------------------------------
42
  def summarize_text(text):
43
  input_text = f"summarize: {text.strip()}"
44
  input_ids = tokenizer_qg.encode(input_text, return_tensors="pt", max_length=512, truncation=True)
45
+ summary_ids = model_qg.generate(input_ids, max_length=150, min_length=30, length_penalty=5.0, num_beams=2)
46
  return tokenizer_qg.decode(summary_ids[0], skip_special_tokens=True)
47
 
48
  # ------------------------------
 
50
  # ------------------------------
51
  def predict_engagement(file):
52
  df = pd.read_csv(file.name)
53
+ avg_time = df["TimeSpent"].mean()
54
+ return "βœ… Engaged student" if avg_time >= 10 else "⚠️ Risk of disengagement"
 
 
 
55
 
56
  # ------------------------------
57
  # Badge Generator
58
  # ------------------------------
59
  def generate_badge(file):
60
  df = pd.read_csv(file.name)
61
+ avg_score = df["Score"].mean()
62
  if avg_score >= 80:
63
  return "πŸ… Gold Badge"
64
  elif avg_score >= 50:
 
84
  return f"Similarity Score: {score:.2f} - {'⚠️ Possible Plagiarism' if score > 0.8 else 'βœ… Looks Original'}"
85
 
86
  # ------------------------------
87
+ # Gradio Interface
88
  # ------------------------------
89
  with gr.Blocks() as demo:
90
  gr.Markdown("# πŸ“š AI-Powered LMS Suite (Offline Mode)")
 
106
  gr.ChatInterface(fn=chatbot_response)
107
 
108
  with gr.Tab("🎀 Speech Q Solver"):
109
+ audio_in = gr.Audio(label="Upload Audio", type="filepath")
110
+ audio_btn = gr.Button("Get Answer")
111
+ audio_out = gr.Textbox(label="Answer")
112
  audio_btn.click(fn=speech_answer, inputs=audio_in, outputs=audio_out)
113
 
114
  with gr.Tab("πŸ“„ Summarizer"):
 
133
  trans_in = gr.Textbox(label="Enter Text")
134
  trans_lang = gr.Textbox(label="Target Language")
135
  trans_btn = gr.Button("Translate")
136
+ tr