sanarawal7 commited on
Commit
a517614
·
1 Parent(s): 5481813
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -5,14 +5,17 @@ from transformers import AutoTokenizer, AutoModelForQuestionAnswering
5
  # Replace with your Hugging Face API token
6
  hf_api_token = "HF_API_KEY"
7
 
8
- def generate_questions(file_content):
9
- # Load MolMo model and tokenizer with API token
10
- model_name = "allenai/Molmo-7B-D-0924"
11
- tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=hf_api_token)
12
- model = AutoModelForQuestionAnswering.from_pretrained(model_name, use_auth_token=hf_api_token)
13
 
 
14
  # Preprocess file content (assuming it's already text)
15
- text = file_content.decode("utf-8")
 
 
 
16
 
17
  # Generate questions and answers
18
  inputs = tokenizer(text, return_tensors="pt")
@@ -31,7 +34,7 @@ def generate_questions(file_content):
31
  return questions, options
32
 
33
  # Create Gradio interface
34
- question_box = gr.Textbox(label="Question")
35
  option_box = gr.Textbox(label="Options")
36
 
37
  iface = gr.Interface(
@@ -41,4 +44,4 @@ iface = gr.Interface(
41
  title="Question and Option Generator"
42
  )
43
 
44
- iface.launch()
 
5
  # Replace with your Hugging Face API token
6
  hf_api_token = "HF_API_KEY"
7
 
8
+ # Load the model and tokenizer globally, not inside the function
9
+ model_name = "allenai/Molmo-7B-D-0924"
10
+ tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=hf_api_token)
11
+ model = AutoModelForQuestionAnswering.from_pretrained(model_name, use_auth_token=hf_api_token)
 
12
 
13
+ def generate_questions(file_content):
14
  # Preprocess file content (assuming it's already text)
15
+ try:
16
+ text = file_content.decode("utf-8")
17
+ except Exception as e:
18
+ return f"Error decoding file: {str(e)}", ""
19
 
20
  # Generate questions and answers
21
  inputs = tokenizer(text, return_tensors="pt")
 
34
  return questions, options
35
 
36
  # Create Gradio interface
37
+ question_box = gr.Textbox(label="Questions")
38
  option_box = gr.Textbox(label="Options")
39
 
40
  iface = gr.Interface(
 
44
  title="Question and Option Generator"
45
  )
46
 
47
+ iface.launch()