GeminiAi commited on
Commit
2a4ebb2
Β·
verified Β·
1 Parent(s): c05ae74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -30
app.py CHANGED
@@ -31,36 +31,87 @@ def answer_question(text, question):
31
  except Exception as e:
32
  return f"Error in question answering: {str(e)}"
33
 
34
- # Gradio interface
35
- def study_assistant(text, task, question=None):
36
- if task == "Summarize":
37
- return summarize(text)
38
- elif task == "Generate Flashcards":
39
- return generate_flashcards(text)
40
- elif task == "Answer Question":
41
- if not question:
42
- return "Please enter a question."
43
- return answer_question(text, question)
44
- else:
45
- return "Invalid task selected."
 
 
 
 
46
 
47
- # Gradio UI
48
- interface = gr.Interface(
49
- fn=study_assistant,
50
- inputs=[
51
- gr.Textbox(lines=10, label="Input Text", placeholder="Paste your text here..."),
52
- gr.Radio(choices=["Summarize", "Generate Flashcards", "Answer Question"], label="Task"),
53
- gr.Textbox(lines=2, label="Question (for Answer Question task)", placeholder="Enter your question here..."),
54
- ],
55
- outputs=gr.Textbox(label="Output"),
56
- title="AI-Powered Study Assistant",
57
- description="Summarize text, generate flashcards, or answer questions using AI!",
58
- examples=[
59
- ["The French Revolution was a period of radical social and political upheaval in France that lasted from 1789 to 1799. It led to the rise of Napoleon Bonaparte and the eventual decline of the French monarchy.", "Summarize"],
60
- ["Photosynthesis is the process by which green plants use sunlight to synthesize foods with the help of chlorophyll. It converts carbon dioxide and water into glucose and oxygen.", "Generate Flashcards"],
61
- ["The Industrial Revolution began in the 18th century and marked a major turning point in history. Almost every aspect of daily life was influenced in some way.", "Answer Question", "When did the Industrial Revolution begin?"],
62
- ],
63
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  # Launch the app
66
- interface.launch()
 
31
  except Exception as e:
32
  return f"Error in question answering: {str(e)}"
33
 
34
+ # Gradio Blocks for advanced UI
35
+ with gr.Blocks(
36
+ theme=gr.themes.Soft(primary_hue="teal", secondary_hue="pink"), # Use a vibrant theme
37
+ css=".gradio-container {background: linear-gradient(135deg, #f5f7fa, #c3cfe2);} "
38
+ ".output-text {font-family: 'Arial', sans-serif; font-size: 16px; color: #333;} "
39
+ ".input-text {font-family: 'Arial', sans-serif; font-size: 16px; color: #555;} "
40
+ "button {background: linear-gradient(135deg, #6a11cb, #2575fc); color: white; border: none; padding: 10px 20px; border-radius: 5px;} "
41
+ "button:hover {background: linear-gradient(135deg, #2575fc, #6a11cb);} "
42
+ ) as demo:
43
+ # Title and description
44
+ gr.Markdown(
45
+ """
46
+ # πŸš€ **AI-Powered Study Assistant**
47
+ **Summarize text, generate flashcards, or answer questions using AI!**
48
+ """
49
+ )
50
 
51
+ # Inputs
52
+ with gr.Row():
53
+ text_input = gr.Textbox(
54
+ lines=10,
55
+ label="πŸ“ **Input Text**",
56
+ placeholder="Paste your text here...",
57
+ elem_classes="input-text"
58
+ )
59
+ question_input = gr.Textbox(
60
+ lines=2,
61
+ label="❓ **Question (for Answer Question task)**",
62
+ placeholder="Enter your question here...",
63
+ elem_classes="input-text"
64
+ )
65
+
66
+ # Task selection
67
+ task_radio = gr.Radio(
68
+ choices=["Summarize", "Generate Flashcards", "Answer Question"],
69
+ label="🎯 **Task**",
70
+ value="Summarize"
71
+ )
72
+
73
+ # Output
74
+ output_text = gr.Textbox(
75
+ label="πŸ“„ **Output**",
76
+ lines=10,
77
+ elem_classes="output-text"
78
+ )
79
+
80
+ # Submit button
81
+ submit_button = gr.Button("✨ **Submit**")
82
+
83
+ # Examples
84
+ gr.Examples(
85
+ examples=[
86
+ ["The French Revolution was a period of radical social and political upheaval in France that lasted from 1789 to 1799. It led to the rise of Napoleon Bonaparte and the eventual decline of the French monarchy.", "Summarize"],
87
+ ["Photosynthesis is the process by which green plants use sunlight to synthesize foods with the help of chlorophyll. It converts carbon dioxide and water into glucose and oxygen.", "Generate Flashcards"],
88
+ ["The Industrial Revolution began in the 18th century and marked a major turning point in history. Almost every aspect of daily life was influenced in some way.", "Answer Question", "When did the Industrial Revolution begin?"],
89
+ ],
90
+ inputs=[text_input, task_radio, question_input],
91
+ outputs=output_text,
92
+ fn=study_assistant,
93
+ label="πŸ“š **Examples**"
94
+ )
95
+
96
+ # Function to handle task selection
97
+ def study_assistant(text, task, question=None):
98
+ if task == "Summarize":
99
+ return summarize(text)
100
+ elif task == "Generate Flashcards":
101
+ return generate_flashcards(text)
102
+ elif task == "Answer Question":
103
+ if not question:
104
+ return "Please enter a question."
105
+ return answer_question(text, question)
106
+ else:
107
+ return "Invalid task selected."
108
+
109
+ # Link button to function
110
+ submit_button.click(
111
+ study_assistant,
112
+ inputs=[text_input, task_radio, question_input],
113
+ outputs=output_text
114
+ )
115
 
116
  # Launch the app
117
+ demo.launch()