Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,12 @@
|
|
1 |
-
import os
|
2 |
import gradio as gr
|
3 |
import google.generativeai as genai
|
4 |
from dotenv import load_dotenv
|
5 |
-
import time
|
6 |
|
7 |
# Load environment variables from .env file
|
8 |
load_dotenv()
|
9 |
|
10 |
# Retrieve API key from environment variable
|
11 |
-
GEMINI_API_KEY = "AIzaSyA0SnGcdEuesDusLiM93N68-vaFF14RCYg"
|
12 |
|
13 |
# Configure Google Gemini API
|
14 |
genai.configure(api_key=GEMINI_API_KEY)
|
@@ -61,23 +59,10 @@ def generate_response(user_input, chat_history):
|
|
61 |
|
62 |
except Exception as e:
|
63 |
if attempt < retry_attempts - 1:
|
64 |
-
time.sleep(2) # Delay before retrying
|
65 |
continue
|
66 |
else:
|
67 |
return f"Error after {retry_attempts} attempts: {str(e)}", chat_history
|
68 |
|
69 |
-
# Build the Gradio interface
|
70 |
-
with gr.
|
71 |
-
|
72 |
-
chat_history_state = gr.State([]) # State input for chat history
|
73 |
-
response_output = gr.Textbox(label="Response")
|
74 |
-
|
75 |
-
# Define the layout and components
|
76 |
-
generate_button = gr.Button("Generate Response")
|
77 |
-
generate_button.click(
|
78 |
-
fn=generate_response,
|
79 |
-
inputs=[chat_input, chat_history_state],
|
80 |
-
outputs=[response_output, chat_history_state]
|
81 |
-
)
|
82 |
-
|
83 |
-
iface.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import google.generativeai as genai
|
3 |
from dotenv import load_dotenv
|
|
|
4 |
|
5 |
# Load environment variables from .env file
|
6 |
load_dotenv()
|
7 |
|
8 |
# Retrieve API key from environment variable
|
9 |
+
GEMINI_API_KEY = "AIzaSyA0SnGcdEuesDusLiM93N68-vaFF14RCYg" # public api
|
10 |
|
11 |
# Configure Google Gemini API
|
12 |
genai.configure(api_key=GEMINI_API_KEY)
|
|
|
59 |
|
60 |
except Exception as e:
|
61 |
if attempt < retry_attempts - 1:
|
|
|
62 |
continue
|
63 |
else:
|
64 |
return f"Error after {retry_attempts} attempts: {str(e)}", chat_history
|
65 |
|
66 |
+
# Build the Gradio interface using ChatInterface
|
67 |
+
with gr.ChatInterface(fn=generate_response) as iface:
|
68 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|