aryandudul commited on
Commit
b3523b4
1 Parent(s): 40d84b9

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from flask import Flask, request, render_template, redirect, url_for
3
+ from PIL import Image
4
+ import google.generativeai as genai
5
+
6
+ # Replace with your actual API key
7
+ GOOGLE_API_KEY = 'AIzaSyDDt5EWkmYlQTCJZfwNPizs0qZDFznSKVU'
8
+
9
+ # Configure the API key
10
+ genai.configure(api_key=GOOGLE_API_KEY)
11
+
12
+ # Select the model you want to use
13
+ model = genai.GenerativeModel('gemini-1.5-flash-latest')
14
+
15
+ app = Flask(__name__)
16
+ app.config['UPLOAD_FOLDER'] = 'uploads'
17
+
18
+ # Ensure the upload folder exists
19
+ os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
20
+
21
+ @app.route('/')
22
+ def index():
23
+ return render_template('index.html')
24
+
25
+ @app.route('/upload', methods=['POST'])
26
+ def upload_file():
27
+ if 'file' not in request.files:
28
+ return redirect(request.url)
29
+
30
+ file = request.files['file']
31
+ if file.filename == '':
32
+ return redirect(request.url)
33
+
34
+ if file:
35
+ filepath = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
36
+ file.save(filepath)
37
+
38
+ img = Image.open(filepath)
39
+
40
+ # Generate content using the model
41
+ response = model.generate_content(["Give the equivalent XML for the UML diagram also take into account all attributes, classes, and functions", img], stream=True)
42
+ response.resolve()
43
+
44
+ return render_template('result.html', result=response.text)
45
+
46
+ if __name__ == '__main__':
47
+ app.run(debug=True)