Spaces:
Configuration error
Configuration error
Zeeshanunique
commited on
Commit
•
05d59df
1
Parent(s):
7424ed2
main
Browse files- .gitattributes +0 -35
- .gitignore +0 -1
- Dockerfile +0 -24
- Procfile +1 -0
- README.md +0 -10
- app.py +21 -21
- requirements.txt +1 -3
- runtime.txt +1 -0
.gitattributes
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
.env
|
|
|
|
Dockerfile
DELETED
@@ -1,24 +0,0 @@
|
|
1 |
-
# Use an official Python runtime as a parent image
|
2 |
-
FROM python:3.9
|
3 |
-
|
4 |
-
# Create a non-root user and set the environment PATH
|
5 |
-
RUN useradd -m -u 1000 user
|
6 |
-
USER user
|
7 |
-
ENV PATH="/home/user/.local/bin:$PATH"
|
8 |
-
ENV GOOGLE_API_KEY=AIzaSyBI_ssWbmxY-WN6Uwqk2KNUwpc6GFJ-wb8
|
9 |
-
ENV SECRET_KEY=your_secret_key
|
10 |
-
|
11 |
-
# Set the working directory in the container
|
12 |
-
WORKDIR /app
|
13 |
-
|
14 |
-
# Copy the requirements file into the container
|
15 |
-
COPY --chown=user ./requirements.txt requirements.txt
|
16 |
-
|
17 |
-
# Install the required packages
|
18 |
-
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
19 |
-
|
20 |
-
# Copy the current directory contents into the container at /app
|
21 |
-
COPY --chown=user . /app
|
22 |
-
|
23 |
-
# Command to run the application using Hypercorn
|
24 |
-
CMD ["hypercorn", "app:app", "--bind", "0.0.0.0:7860"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Procfile
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
web: python app.py
|
README.md
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
---
|
2 |
-
title: QuizWiz
|
3 |
-
emoji: 📈
|
4 |
-
colorFrom: purple
|
5 |
-
colorTo: pink
|
6 |
-
sdk: docker
|
7 |
-
pinned: false
|
8 |
-
---
|
9 |
-
|
10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -4,7 +4,6 @@ from dotenv import load_dotenv
|
|
4 |
import os
|
5 |
import json
|
6 |
import google.generativeai as genai
|
7 |
-
from asgiref.wsgi import WsgiToAsgi
|
8 |
|
9 |
# Load environment variables
|
10 |
load_dotenv()
|
@@ -13,9 +12,8 @@ load_dotenv()
|
|
13 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
14 |
|
15 |
app = Flask(__name__)
|
16 |
-
|
17 |
CORS(app)
|
18 |
-
app.secret_key = os.getenv("SECRET_KEY", "fallback_secret_key")
|
19 |
|
20 |
def get_gemini_response(input_text):
|
21 |
model = genai.GenerativeModel("gemini-1.5-flash", generation_config={"response_mime_type": "application/json"})
|
@@ -28,7 +26,7 @@ def generate_quiz():
|
|
28 |
quiz_data = request.json
|
29 |
if not quiz_data:
|
30 |
return jsonify({"error": "No data received"}), 400
|
31 |
-
|
32 |
prompt = f"""
|
33 |
Create a quiz with the following parameters:
|
34 |
- Target audience: {quiz_data['quiz_for']}
|
@@ -40,25 +38,29 @@ def generate_quiz():
|
|
40 |
|
41 |
Use this JSON schema:
|
42 |
{{
|
43 |
-
"
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
46 |
}}
|
47 |
-
|
48 |
Return a list of {quiz_data['numQuestions']} questions following this schema.
|
49 |
"""
|
50 |
-
|
51 |
raw_response = get_gemini_response(prompt)
|
52 |
-
print("Raw Response from Gemini:", raw_response)
|
53 |
-
|
54 |
data = json.loads(raw_response)
|
55 |
-
session['questions'] = data
|
56 |
return jsonify(data)
|
57 |
except json.JSONDecodeError as e:
|
58 |
-
print("JSON Decode Error:", e)
|
59 |
return jsonify({"error": "Error parsing the response. Please try again."}), 400
|
60 |
except Exception as e:
|
61 |
-
print("Error:", e)
|
62 |
return jsonify({"error": "An error occurred. Please try again."}), 500
|
63 |
|
64 |
@app.route('/submit_quiz', methods=['POST'])
|
@@ -72,9 +74,9 @@ def submit_quiz():
|
|
72 |
score = 0
|
73 |
results = []
|
74 |
|
75 |
-
for idx, question in enumerate(questions
|
76 |
-
correct_answer = question['
|
77 |
-
user_answer = user_answers.get(f"
|
78 |
is_correct = user_answer == correct_answer
|
79 |
if is_correct:
|
80 |
score += 1
|
@@ -87,10 +89,8 @@ def submit_quiz():
|
|
87 |
|
88 |
return jsonify({"results": results, "score": score, "total": len(questions)})
|
89 |
except Exception as e:
|
90 |
-
print("Error:", e)
|
91 |
return jsonify({"error": "An error occurred. Please try again."}), 500
|
92 |
|
93 |
if __name__ == '__main__':
|
94 |
-
|
95 |
-
hypercorn.asyncio.serve(WsgiToAsgi(app), hypercorn.Config.from_mapping(bind=["0.0.0.0:7860"]))
|
96 |
-
app.run(host='0.0.0.0', port=7860)
|
|
|
4 |
import os
|
5 |
import json
|
6 |
import google.generativeai as genai
|
|
|
7 |
|
8 |
# Load environment variables
|
9 |
load_dotenv()
|
|
|
12 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
13 |
|
14 |
app = Flask(__name__)
|
|
|
15 |
CORS(app)
|
16 |
+
app.secret_key = os.getenv("SECRET_KEY", "fallback_secret_key")
|
17 |
|
18 |
def get_gemini_response(input_text):
|
19 |
model = genai.GenerativeModel("gemini-1.5-flash", generation_config={"response_mime_type": "application/json"})
|
|
|
26 |
quiz_data = request.json
|
27 |
if not quiz_data:
|
28 |
return jsonify({"error": "No data received"}), 400
|
29 |
+
|
30 |
prompt = f"""
|
31 |
Create a quiz with the following parameters:
|
32 |
- Target audience: {quiz_data['quiz_for']}
|
|
|
38 |
|
39 |
Use this JSON schema:
|
40 |
{{
|
41 |
+
"questions": [
|
42 |
+
{{
|
43 |
+
"question": "str",
|
44 |
+
"options": ["str", "str", "str", "str"],
|
45 |
+
"correct_answer": "str"
|
46 |
+
}}
|
47 |
+
]
|
48 |
}}
|
49 |
+
|
50 |
Return a list of {quiz_data['numQuestions']} questions following this schema.
|
51 |
"""
|
52 |
+
|
53 |
raw_response = get_gemini_response(prompt)
|
54 |
+
print("Raw Response from Gemini:", raw_response)
|
55 |
+
|
56 |
data = json.loads(raw_response)
|
57 |
+
session['questions'] = data['questions']
|
58 |
return jsonify(data)
|
59 |
except json.JSONDecodeError as e:
|
60 |
+
print("JSON Decode Error:", e)
|
61 |
return jsonify({"error": "Error parsing the response. Please try again."}), 400
|
62 |
except Exception as e:
|
63 |
+
print("Error:", e)
|
64 |
return jsonify({"error": "An error occurred. Please try again."}), 500
|
65 |
|
66 |
@app.route('/submit_quiz', methods=['POST'])
|
|
|
74 |
score = 0
|
75 |
results = []
|
76 |
|
77 |
+
for idx, question in enumerate(questions):
|
78 |
+
correct_answer = question['correct_answer']
|
79 |
+
user_answer = user_answers.get(f"question_{idx}")
|
80 |
is_correct = user_answer == correct_answer
|
81 |
if is_correct:
|
82 |
score += 1
|
|
|
89 |
|
90 |
return jsonify({"results": results, "score": score, "total": len(questions)})
|
91 |
except Exception as e:
|
92 |
+
print("Error:", e)
|
93 |
return jsonify({"error": "An error occurred. Please try again."}), 500
|
94 |
|
95 |
if __name__ == '__main__':
|
96 |
+
app.run(debug=True)
|
|
|
|
requirements.txt
CHANGED
@@ -1,6 +1,4 @@
|
|
1 |
google-generativeai
|
2 |
python-dotenv
|
3 |
Flask
|
4 |
-
flask_cors
|
5 |
-
asgiref
|
6 |
-
hypercorn
|
|
|
1 |
google-generativeai
|
2 |
python-dotenv
|
3 |
Flask
|
4 |
+
flask_cors
|
|
|
|
runtime.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
python-3.11.9
|