sanarawal7 commited on
Commit
d2db563
·
1 Parent(s): 0fbdd72

adding appns

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +60 -0
  3. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .env
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ import gradio as gr
4
+ from dotenv import load_dotenv
5
+
6
+ # Load environment variables from .env file
7
+ load_dotenv()
8
+
9
+ # Get the Hugging Face API key from environment variables
10
+ hf_api_key = os.getenv("HF_API_KEY")
11
+
12
+ # Ensure the API key is loaded correctly
13
+ if hf_api_key is None:
14
+ raise ValueError("Hugging Face API key not found. Please set it in the .env file.")
15
+
16
+ # Hugging Face Inference API URL for the model
17
+ api_url = "https://api-inference.huggingface.co/models/allenai/Molmo-7B-D-0924"
18
+
19
+ # Function to generate questions based on the input text using the Hugging Face API
20
+ def generate_question(text):
21
+ headers = {
22
+ "Authorization": f"Bearer {hf_api_key}",
23
+ "Content-Type": "application/json",
24
+ }
25
+
26
+ # Payload for the request
27
+ data = {
28
+ "inputs": text,
29
+ "parameters": {"max_length": 100, "do_sample": False},
30
+ }
31
+
32
+ # Make the request to the Hugging Face API
33
+ response = requests.post(api_url, headers=headers, json=data)
34
+
35
+ if response.status_code == 200:
36
+ result = response.json()
37
+ return result[0]["generated_text"]
38
+ else:
39
+ return f"Error: {response.status_code} - {response.text}"
40
+
41
+ # Function to handle file input, read its contents, and generate questions
42
+ def handle_file(file):
43
+ # Read the content of the file
44
+ file_text = file.read().decode("utf-8") # Assuming it's a text file
45
+ # Generate a question based on the file content
46
+ question = generate_question(file_text)
47
+ return question
48
+
49
+ # Gradio interface to accept a file and generate questions
50
+ interface = gr.Interface(
51
+ fn=handle_file,
52
+ inputs=gr.File(label="Upload a text file"),
53
+ outputs="text",
54
+ title="Quiz Question Generator",
55
+ description="Upload a file and the AI will generate quiz questions based on the text."
56
+ )
57
+
58
+ # Launch the Gradio app
59
+ if __name__ == "__main__":
60
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ requests
3
+ python-dotenv