Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -285,12 +285,12 @@
|
|
285 |
|
286 |
# if __name__ == "__main__":
|
287 |
# iface.launch()
|
288 |
-
|
289 |
import os
|
290 |
from mistralai.client import MistralClient
|
291 |
from mistralai.models.chat_completion import ChatMessage
|
292 |
|
293 |
-
#
|
294 |
api_key = os.getenv("MISTRAL_API_KEY")
|
295 |
if not api_key:
|
296 |
raise ValueError("MISTRAL_API_KEY environment variable not set")
|
@@ -298,20 +298,17 @@ if not api_key:
|
|
298 |
model = "mistral-tiny"
|
299 |
client = MistralClient(api_key=api_key)
|
300 |
|
301 |
-
app = Flask(__name__)
|
302 |
-
|
303 |
def generate_goals(input_var):
|
304 |
messages = [
|
305 |
ChatMessage(role="user", content=f"Generate 5 specific, industry relevant goals for {input_var} using Python and Pandas in exam data analysis. Each goal should include a brief name and a one-sentence description of the task or skill.")
|
306 |
]
|
307 |
-
|
308 |
try:
|
309 |
response = client.chat(model=model, messages=messages)
|
310 |
-
|
311 |
-
return content
|
312 |
except Exception as e:
|
313 |
return f"An error occurred: {str(e)}"
|
314 |
|
|
|
315 |
# HTML content with interactive visualization
|
316 |
html_content = """
|
317 |
<!DOCTYPE html>
|
@@ -511,15 +508,15 @@ html_content = """
|
|
511 |
</html>
|
512 |
"""
|
513 |
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
|
524 |
-
|
525 |
-
|
|
|
285 |
|
286 |
# if __name__ == "__main__":
|
287 |
# iface.launch()
|
288 |
+
import gradio as gr
|
289 |
import os
|
290 |
from mistralai.client import MistralClient
|
291 |
from mistralai.models.chat_completion import ChatMessage
|
292 |
|
293 |
+
# Mistral AI setup
|
294 |
api_key = os.getenv("MISTRAL_API_KEY")
|
295 |
if not api_key:
|
296 |
raise ValueError("MISTRAL_API_KEY environment variable not set")
|
|
|
298 |
model = "mistral-tiny"
|
299 |
client = MistralClient(api_key=api_key)
|
300 |
|
|
|
|
|
301 |
def generate_goals(input_var):
|
302 |
messages = [
|
303 |
ChatMessage(role="user", content=f"Generate 5 specific, industry relevant goals for {input_var} using Python and Pandas in exam data analysis. Each goal should include a brief name and a one-sentence description of the task or skill.")
|
304 |
]
|
|
|
305 |
try:
|
306 |
response = client.chat(model=model, messages=messages)
|
307 |
+
return response.choices[0].message.content
|
|
|
308 |
except Exception as e:
|
309 |
return f"An error occurred: {str(e)}"
|
310 |
|
311 |
+
|
312 |
# HTML content with interactive visualization
|
313 |
html_content = """
|
314 |
<!DOCTYPE html>
|
|
|
508 |
</html>
|
509 |
"""
|
510 |
|
511 |
+
# Gradio interface
|
512 |
+
iface = gr.Interface(
|
513 |
+
fn=generate_goals,
|
514 |
+
inputs="text",
|
515 |
+
outputs="text",
|
516 |
+
title="Exam Data Analysis Goals Generator",
|
517 |
+
description="Click on a goal in the visualization to generate related goals.",
|
518 |
+
article=html_content
|
519 |
+
)
|
520 |
|
521 |
+
# Launch the Gradio app
|
522 |
+
iface.launch()
|