SameerArz commited on
Commit
b5ecd6f
verified
1 Parent(s): 74a208a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -1,13 +1,25 @@
1
  import gradio as gr
2
  from groq import Groq
3
  import os
4
- import openai # For integration with OpenAI's image generation API (e.g., DALL路E)
5
 
6
  # Initialize Groq client
7
  client = Groq(api_key=os.environ["GROQ_API_KEY"])
8
 
9
- # Initialize OpenAI API client for image generation
10
- openai.api_key = os.environ["OPENAI_API_KEY"]
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  def generate_tutor_output(subject, difficulty, student_input):
13
  prompt = f"""
@@ -39,15 +51,6 @@ def generate_tutor_output(subject, difficulty, student_input):
39
 
40
  return completion.choices[0].message.content
41
 
42
- def generate_visual_answer(prompt):
43
- response = openai.Image.create(
44
- prompt=prompt,
45
- n=1,
46
- size="1024x1024"
47
- )
48
- image_url = response['data'][0]['url']
49
- return image_url
50
-
51
  with gr.Blocks() as demo:
52
  gr.Markdown("# 馃帗 Your AI Tutor by Farhan")
53
 
@@ -89,7 +92,7 @@ with gr.Blocks() as demo:
89
  def process_output(output, prompt):
90
  try:
91
  parsed = eval(output)
92
- visual_answer = generate_visual_answer(prompt) # Get the image URL
93
  return parsed["lesson"], parsed["question"], parsed["feedback"], visual_answer
94
  except:
95
  return "Error parsing output", "No question available", "No feedback available", None
 
1
  import gradio as gr
2
  from groq import Groq
3
  import os
4
+ import requests # For DeepAI API
5
 
6
  # Initialize Groq client
7
  client = Groq(api_key=os.environ["GROQ_API_KEY"])
8
 
9
+ # Function to generate image from DeepAI API
10
+ def generate_visual_answer(prompt):
11
+ # Replace with DeepAI image generation API URL
12
+ url = "https://api.deepai.org/api/text2img"
13
+ response = requests.post(
14
+ url,
15
+ data={'text': prompt}, # The prompt will be the text description for image generation
16
+ headers={'api-key': os.environ["DEEP_AI_API_KEY"]} # Use DeepAI's API key here
17
+ )
18
+ if response.status_code == 200:
19
+ image_url = response.json()['output_url'] # URL for the generated image
20
+ return image_url
21
+ else:
22
+ return "Error generating image"
23
 
24
  def generate_tutor_output(subject, difficulty, student_input):
25
  prompt = f"""
 
51
 
52
  return completion.choices[0].message.content
53
 
 
 
 
 
 
 
 
 
 
54
  with gr.Blocks() as demo:
55
  gr.Markdown("# 馃帗 Your AI Tutor by Farhan")
56
 
 
92
  def process_output(output, prompt):
93
  try:
94
  parsed = eval(output)
95
+ visual_answer = generate_visual_answer(prompt) # Get the image URL from DeepAI
96
  return parsed["lesson"], parsed["question"], parsed["feedback"], visual_answer
97
  except:
98
  return "Error parsing output", "No question available", "No feedback available", None