mimoha commited on
Commit
f2c0b26
·
verified ·
1 Parent(s): 9ba43c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
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 os
7
 
8
- genai.configure(api_key=os.environ["AIzaSyDedY-PdSeTyitSztgMl7MubbELhffNx7c"])
9
- model = genai.GenerativeModel("gemini-1.5-flash")
 
 
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 = model.generate_content(prompt)
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(share=True, show_error=True)
 
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()