Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,19 +6,16 @@ from typing import Dict
|
|
| 6 |
import hashlib
|
| 7 |
from openai import OpenAI
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
-
import os
|
| 10 |
-
load_dotenv()
|
| 11 |
-
client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
|
| 12 |
-
# from pathlib import Path
|
| 13 |
-
# from langchain_community.document_loaders import WebBaseLoade as genai
|
| 14 |
-
import os
|
| 15 |
-
import re
|
| 16 |
-
import pandas as pd
|
| 17 |
from fastapi.middleware.cors import CORSMiddleware
|
| 18 |
from firebase_admin import firestore
|
| 19 |
import json
|
|
|
|
|
|
|
| 20 |
import google.generativeai as genai
|
| 21 |
from google.generativeai import GenerativeModel
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Initialize Gemini LLM
|
| 24 |
# load_dotenv()
|
|
@@ -29,9 +26,6 @@ model = genai.GenerativeModel("gemini-2.0-flash")
|
|
| 29 |
import firebase_admin
|
| 30 |
from firebase_admin import credentials
|
| 31 |
|
| 32 |
-
cred_dic = os.getenv("Firebase_cred")
|
| 33 |
-
|
| 34 |
-
cred_dict = json.loads(cred_dic)
|
| 35 |
# cred = credentials.Certificate("/content/ir-502e5-firebase-adminsdk-3der0-0145a61d7a.json")
|
| 36 |
# firebase_admin.initialize_app(cred)
|
| 37 |
|
|
@@ -46,7 +40,7 @@ app.add_middleware(
|
|
| 46 |
)
|
| 47 |
def generate_df():
|
| 48 |
data = []
|
| 49 |
-
cred = credentials.Certificate(
|
| 50 |
firebase_admin.initialize_app(cred)
|
| 51 |
db = firestore.client()
|
| 52 |
docs = db.collection("test_results").get()
|
|
@@ -113,8 +107,11 @@ async def get_overall_feedback(email: str):
|
|
| 113 |
async def get_strong_weak_topics(email: str):
|
| 114 |
df = generate_df()
|
| 115 |
df_email = df[df['email'] == email]
|
| 116 |
-
if
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
| 118 |
# Assuming response is a list of responses
|
| 119 |
formatted_data = str(response) # Convert response to a string format suitable for the API call
|
| 120 |
section_info = {
|
|
@@ -127,14 +124,14 @@ async def get_strong_weak_topics(email: str):
|
|
| 127 |
|
| 128 |
# Generate response using the client
|
| 129 |
completion = client.chat.completions.create(
|
| 130 |
-
model="
|
| 131 |
response_format={"type": "json_object"},
|
| 132 |
messages=[
|
| 133 |
{
|
| 134 |
"role": "system",
|
| 135 |
"content": f"""You are an Educational Performance Analyst focusing on {section_info['filename'].replace('_', ' ')}.
|
| 136 |
Analyze the provided student responses to identify and categorize topics into 'weak' and 'strong' based on their performance. Try to give
|
| 137 |
-
high level
|
| 138 |
Do not add any explanations, introduction, or comments - return ONLY valid JSON.
|
| 139 |
"""
|
| 140 |
},
|
|
|
|
| 6 |
import hashlib
|
| 7 |
from openai import OpenAI
|
| 8 |
from dotenv import load_dotenv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
| 10 |
from firebase_admin import firestore
|
| 11 |
import json
|
| 12 |
+
import re
|
| 13 |
+
import pandas as pd
|
| 14 |
import google.generativeai as genai
|
| 15 |
from google.generativeai import GenerativeModel
|
| 16 |
+
import os
|
| 17 |
+
load_dotenv()
|
| 18 |
+
client = OpenAI(api_key=os.getenv('DEEPSEEK_API_KEY'), base_url="https://api.deepseek.com",)
|
| 19 |
|
| 20 |
# Initialize Gemini LLM
|
| 21 |
# load_dotenv()
|
|
|
|
| 26 |
import firebase_admin
|
| 27 |
from firebase_admin import credentials
|
| 28 |
|
|
|
|
|
|
|
|
|
|
| 29 |
# cred = credentials.Certificate("/content/ir-502e5-firebase-adminsdk-3der0-0145a61d7a.json")
|
| 30 |
# firebase_admin.initialize_app(cred)
|
| 31 |
|
|
|
|
| 40 |
)
|
| 41 |
def generate_df():
|
| 42 |
data = []
|
| 43 |
+
cred = credentials.Certificate("G:/Cognozire/Alguru/Feeback_Api's/fir-502e5-firebase-adminsdk-3der0-0145a61d7a.json")
|
| 44 |
firebase_admin.initialize_app(cred)
|
| 45 |
db = firestore.client()
|
| 46 |
docs = db.collection("test_results").get()
|
|
|
|
| 107 |
async def get_strong_weak_topics(email: str):
|
| 108 |
df = generate_df()
|
| 109 |
df_email = df[df['email'] == email]
|
| 110 |
+
if len(df_email)<10:
|
| 111 |
+
return JSONResponse(content={"message": "Please attempt atleast 10 tests to enable this feature"})
|
| 112 |
+
|
| 113 |
+
elif len(df)>=10:
|
| 114 |
+
response = df_email['responses'].values[:10]
|
| 115 |
# Assuming response is a list of responses
|
| 116 |
formatted_data = str(response) # Convert response to a string format suitable for the API call
|
| 117 |
section_info = {
|
|
|
|
| 124 |
|
| 125 |
# Generate response using the client
|
| 126 |
completion = client.chat.completions.create(
|
| 127 |
+
model="deepseek-chat",
|
| 128 |
response_format={"type": "json_object"},
|
| 129 |
messages=[
|
| 130 |
{
|
| 131 |
"role": "system",
|
| 132 |
"content": f"""You are an Educational Performance Analyst focusing on {section_info['filename'].replace('_', ' ')}.
|
| 133 |
Analyze the provided student responses to identify and categorize topics into 'weak' and 'strong' based on their performance. Try to give
|
| 134 |
+
high level topics like algebra, trignometry, geometry etc in your response.
|
| 135 |
Do not add any explanations, introduction, or comments - return ONLY valid JSON.
|
| 136 |
"""
|
| 137 |
},
|