Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,9 @@
|
|
1 |
-
# Requirement: !pip install gradio, groq
|
2 |
-
|
3 |
# 1. Imports and API setup
|
4 |
import gradio as gr
|
5 |
from groq import Groq
|
6 |
import base64
|
7 |
import os
|
8 |
-
import spaces
|
9 |
|
10 |
# Define models used in the process
|
11 |
llava_model = 'llava-v1.5-7b-4096-preview'
|
@@ -17,6 +15,7 @@ def encode_image(image_path):
|
|
17 |
return base64.b64encode(image_file.read()).decode('utf-8')
|
18 |
|
19 |
# Image to text function
|
|
|
20 |
def image_to_text(client, model, base64_image, prompt):
|
21 |
try:
|
22 |
chat_completion = client.chat.completions.create(
|
@@ -43,6 +42,7 @@ def image_to_text(client, model, base64_image, prompt):
|
|
43 |
return f"Error generating text from image: {str(e)}"
|
44 |
|
45 |
# Technical review generation function
|
|
|
46 |
def technical_review_generation(client, image_description):
|
47 |
keywords = ["econometrics", "finance", "marketing", "stock", "prediction", "chart", "graph", "time series"]
|
48 |
if not any(keyword in image_description.lower() for keyword in keywords):
|
@@ -119,7 +119,6 @@ css = """
|
|
119 |
"""
|
120 |
|
121 |
# Gradio Interface
|
122 |
-
|
123 |
def gradio_interface():
|
124 |
# Define the footer HTML
|
125 |
footer = """
|
@@ -132,7 +131,7 @@ def gradio_interface():
|
|
132 |
Made with π by Pejman Ebrahimi
|
133 |
</div>
|
134 |
"""
|
135 |
-
|
136 |
with gr.Blocks(theme="gradio/soft", css=css) as demo:
|
137 |
gr.HTML("<h1 id='title'>GroqLLaVA Econometrics Agent</h1>")
|
138 |
gr.HTML("<p id='description'>Upload an economic chart and get a detailed analysis using Groq + LLaVA V1.5 7B multimodal.</p>")
|
|
|
|
|
|
|
1 |
# 1. Imports and API setup
|
2 |
import gradio as gr
|
3 |
from groq import Groq
|
4 |
import base64
|
5 |
import os
|
6 |
+
import spaces # Import spaces for ZeroGPU
|
7 |
|
8 |
# Define models used in the process
|
9 |
llava_model = 'llava-v1.5-7b-4096-preview'
|
|
|
15 |
return base64.b64encode(image_file.read()).decode('utf-8')
|
16 |
|
17 |
# Image to text function
|
18 |
+
@spaces.GPU # Decorate this function to use ZeroGPU
|
19 |
def image_to_text(client, model, base64_image, prompt):
|
20 |
try:
|
21 |
chat_completion = client.chat.completions.create(
|
|
|
42 |
return f"Error generating text from image: {str(e)}"
|
43 |
|
44 |
# Technical review generation function
|
45 |
+
@spaces.GPU # Decorate this function to use ZeroGPU
|
46 |
def technical_review_generation(client, image_description):
|
47 |
keywords = ["econometrics", "finance", "marketing", "stock", "prediction", "chart", "graph", "time series"]
|
48 |
if not any(keyword in image_description.lower() for keyword in keywords):
|
|
|
119 |
"""
|
120 |
|
121 |
# Gradio Interface
|
|
|
122 |
def gradio_interface():
|
123 |
# Define the footer HTML
|
124 |
footer = """
|
|
|
131 |
Made with π by Pejman Ebrahimi
|
132 |
</div>
|
133 |
"""
|
134 |
+
|
135 |
with gr.Blocks(theme="gradio/soft", css=css) as demo:
|
136 |
gr.HTML("<h1 id='title'>GroqLLaVA Econometrics Agent</h1>")
|
137 |
gr.HTML("<p id='description'>Upload an economic chart and get a detailed analysis using Groq + LLaVA V1.5 7B multimodal.</p>")
|