Shaneelahi2344 commited on
Commit
1bfff27
·
verified ·
1 Parent(s): dfba79d

requirements.txt

Browse files

gradio
requests
matplotlib

Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import matplotlib.pyplot as plt
4
+ import io
5
+
6
+ API_KEY = "AIzaSyB_mGS8XANkAnb486014uIDf0tMG64eLX0"
7
+
8
+ def generate_plot(text_prompt):
9
+ # Gemini prompt
10
+ gemini_prompt = f"Generate Python matplotlib code to visualize: {text_prompt}"
11
+
12
+ url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key={API_KEY}"
13
+ headers = {"Content-Type": "application/json"}
14
+ data = {
15
+ "contents": [{"parts": [{"text": gemini_prompt}]}]
16
+ }
17
+
18
+ # Gemini response
19
+ response = requests.post(url, headers=headers, json=data)
20
+ code = response.json()['candidates'][0]['content']['parts'][0]['text']
21
+
22
+ # Plot from Gemini code
23
+ plt.clf()
24
+ exec(code, globals())
25
+
26
+ # Save plot as image
27
+ buf = io.BytesIO()
28
+ plt.savefig(buf, format='png')
29
+ buf.seek(0)
30
+
31
+ return buf.getvalue()
32
+
33
+ gr.Interface(fn=generate_plot,
34
+ inputs=gr.Textbox(label="Describe the Data to Visualize"),
35
+ outputs=gr.Image(type="file", label="Generated Graph"),
36
+ title="Text to Graph using Gemini AI").launch()