Spaces:
Sleeping
Sleeping
init
Browse files- app.py +35 -4
- requirements.txt +1 -0
app.py
CHANGED
@@ -16,6 +16,10 @@ import pandas as pd
|
|
16 |
import re
|
17 |
import time
|
18 |
|
|
|
|
|
|
|
|
|
19 |
# From other files
|
20 |
from storage_service import GoogleCloudStorage
|
21 |
from assignment_ui import create_assignment_ui
|
@@ -56,6 +60,19 @@ OPEN_AI_MODERATION_CLIENT = OpenAI(api_key=OPEN_AI_MODERATION_BOT1)
|
|
56 |
GCS_SERVICE = GoogleCloudStorage(GCS_KEY)
|
57 |
GCS_CLIENT = GCS_SERVICE.client
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
_AssignmentService = AssignmentService(GCS_SERVICE)
|
60 |
_SubmissionService = SubmissionService(GCS_SERVICE)
|
61 |
_DashboardService = DashboardService(_AssignmentService, _SubmissionService)
|
@@ -171,11 +188,25 @@ def generate_topics(model, max_tokens, sys_content, scenario, eng_level, user_ge
|
|
171 |
}
|
172 |
|
173 |
try:
|
174 |
-
response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
|
175 |
-
content = response.choices[0].message.content
|
176 |
-
topics = json.loads(content)["topics"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
print(f"====generate_topics====")
|
178 |
-
print(
|
|
|
|
|
|
|
|
|
179 |
gr_update = gr.update(choices=topics, visible=True)
|
180 |
except Exception as e:
|
181 |
print(f"An error occurred while generating topics: {e}")
|
|
|
16 |
import re
|
17 |
import time
|
18 |
|
19 |
+
from google.oauth2.service_account import Credentials
|
20 |
+
import vertexai
|
21 |
+
from vertexai.generative_models import GenerativeModel
|
22 |
+
|
23 |
# From other files
|
24 |
from storage_service import GoogleCloudStorage
|
25 |
from assignment_ui import create_assignment_ui
|
|
|
60 |
GCS_SERVICE = GoogleCloudStorage(GCS_KEY)
|
61 |
GCS_CLIENT = GCS_SERVICE.client
|
62 |
|
63 |
+
# Google aiplatform
|
64 |
+
google_service_account_info_dict = json.loads(GCS_KEY)
|
65 |
+
GOOGPE_SCOPES = ["https://www.googleapis.com/auth/cloud-platform"]
|
66 |
+
google_creds = Credentials.from_service_account_info(
|
67 |
+
google_service_account_info_dict, scopes=GOOGPE_SCOPES
|
68 |
+
)
|
69 |
+
vertexai.init(
|
70 |
+
project="junyiacademy",
|
71 |
+
service_account=google_service_account_info_dict,
|
72 |
+
credentials=google_creds,
|
73 |
+
)
|
74 |
+
|
75 |
+
|
76 |
_AssignmentService = AssignmentService(GCS_SERVICE)
|
77 |
_SubmissionService = SubmissionService(GCS_SERVICE)
|
78 |
_DashboardService = DashboardService(_AssignmentService, _SubmissionService)
|
|
|
188 |
}
|
189 |
|
190 |
try:
|
191 |
+
# response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
|
192 |
+
# content = response.choices[0].message.content
|
193 |
+
# topics = json.loads(content)["topics"]
|
194 |
+
# print(f"====generate_topics====")
|
195 |
+
# print(topics)
|
196 |
+
# gr_update = gr.update(choices=topics, visible=True)
|
197 |
+
|
198 |
+
model_name = "gemini-1.5-pro"
|
199 |
+
gemini_model = GenerativeModel(model_name=model_name)
|
200 |
+
model_response = gemini_model.generate_content(
|
201 |
+
f"{sys_content}, {user_content}"
|
202 |
+
)
|
203 |
+
content = model_response.candidates[0].content.parts[0].text
|
204 |
print(f"====generate_topics====")
|
205 |
+
print(content)
|
206 |
+
print("=====")
|
207 |
+
if "```json" in content:
|
208 |
+
content = content.replace("```json", "").replace("```", "")
|
209 |
+
topics = json.loads(content)["topics"]
|
210 |
gr_update = gr.update(choices=topics, visible=True)
|
211 |
except Exception as e:
|
212 |
print(f"An error occurred while generating topics: {e}")
|
requirements.txt
CHANGED
@@ -6,5 +6,6 @@ google-auth-httplib2
|
|
6 |
google-auth-oauthlib
|
7 |
google-cloud-storage
|
8 |
google-cloud-bigquery
|
|
|
9 |
|
10 |
fastapi==0.112.2
|
|
|
6 |
google-auth-oauthlib
|
7 |
google-cloud-storage
|
8 |
google-cloud-bigquery
|
9 |
+
vertexai
|
10 |
|
11 |
fastapi==0.112.2
|