harris1 commited on
Commit
e4daf67
1 Parent(s): ae0d257

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -18
app.py CHANGED
@@ -285,12 +285,12 @@
285
 
286
  # if __name__ == "__main__":
287
  # iface.launch()
288
- from flask import Flask, request, jsonify, render_template_string
289
  import os
290
  from mistralai.client import MistralClient
291
  from mistralai.models.chat_completion import ChatMessage
292
 
293
- # Ensure the environment variable for the API key is set
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
- content = response.choices[0].message.content
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
- @app.route('/')
515
- def index():
516
- return render_template_string(html_content)
517
-
518
- @app.route('/generate_goals', methods=['POST'])
519
- def generate_goals_api():
520
- input_var = request.json['input_var']
521
- goals = generate_goals(input_var)
522
- return jsonify({'goals': goals})
523
 
524
- if __name__ == "__main__":
525
- app.run(host='0.0.0.0', port=5000, debug=True)
 
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()