Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
# app.py
|
| 2 |
-
import google.generativeai as genai
|
| 3 |
import gradio as gr
|
| 4 |
import json
|
| 5 |
import re
|
| 6 |
-
import
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
def generate_mcqs_gemini(paragraph: str, n_questions: int, n_choices: int = 4):
|
|
@@ -34,7 +35,7 @@ def generate_mcqs_gemini(paragraph: str, n_questions: int, n_choices: int = 4):
|
|
| 34 |
"""
|
| 35 |
|
| 36 |
try:
|
| 37 |
-
response =
|
| 38 |
raw_text = response.text.strip()
|
| 39 |
cleaned = re.sub(r"```(json)?", "", raw_text).strip("` \n")
|
| 40 |
data = json.loads(cleaned)
|
|
@@ -82,4 +83,4 @@ with gr.Blocks() as demo:
|
|
| 82 |
)
|
| 83 |
|
| 84 |
if __name__ == "__main__":
|
| 85 |
-
demo.launch(
|
|
|
|
| 1 |
# app.py
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import json
|
| 4 |
import re
|
| 5 |
+
from google import genai
|
| 6 |
|
| 7 |
+
API_KEY = "AIzaSyDedY-PdSeTyitSztgMl7MubbELhffNx7c"
|
| 8 |
+
|
| 9 |
+
client = genai.Client(api_key=API_KEY)
|
| 10 |
+
MODEL_NAME = "gemini-1.5-flash"
|
| 11 |
|
| 12 |
|
| 13 |
def generate_mcqs_gemini(paragraph: str, n_questions: int, n_choices: int = 4):
|
|
|
|
| 35 |
"""
|
| 36 |
|
| 37 |
try:
|
| 38 |
+
response = client.models.generate_content(model=MODEL_NAME, contents=prompt)
|
| 39 |
raw_text = response.text.strip()
|
| 40 |
cleaned = re.sub(r"```(json)?", "", raw_text).strip("` \n")
|
| 41 |
data = json.loads(cleaned)
|
|
|
|
| 83 |
)
|
| 84 |
|
| 85 |
if __name__ == "__main__":
|
| 86 |
+
demo.launch()
|