Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,52 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
with gr.Blocks() as demo:
|
12 |
-
gr.Markdown("#
|
13 |
-
with gr.Tab("
|
14 |
prompt_input = gr.Textbox(label="Your Prompt:", placeholder="Enter your prompt here", lines=5)
|
15 |
-
generate_button = gr.Button("Generate
|
16 |
-
output_text = gr.Textbox(label="Generated
|
17 |
-
generate_button.click(
|
18 |
|
|
|
19 |
if __name__ == "__main__":
|
20 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
|
5 |
+
# Replace with your actual API key
|
6 |
+
api_key = "YOUR_GEMINI_API_KEY"
|
7 |
|
8 |
+
# Define the API endpoint and headers
|
9 |
+
url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key={api_key}"
|
10 |
+
headers = {
|
11 |
+
'Content-Type': 'application/json'
|
12 |
+
}
|
13 |
|
14 |
+
def generate_prompt(prompt):
|
15 |
+
# Prepare the request body
|
16 |
+
data = {
|
17 |
+
"contents": [
|
18 |
+
{
|
19 |
+
"parts": [
|
20 |
+
{
|
21 |
+
"text": prompt
|
22 |
+
}
|
23 |
+
]
|
24 |
+
}
|
25 |
+
]
|
26 |
+
}
|
27 |
+
|
28 |
+
# Send the POST request
|
29 |
+
response = requests.post(url, headers=headers, data=json.dumps(data))
|
30 |
+
|
31 |
+
# Check if the request was successful
|
32 |
+
if response.status_code == 200:
|
33 |
+
response_data = response.json()
|
34 |
+
generated_text = response_data['candidates']['content']
|
35 |
+
return generated_text
|
36 |
+
else:
|
37 |
+
print(f"Error: {response.status_code}")
|
38 |
+
print(response.text)
|
39 |
+
return None
|
40 |
+
|
41 |
+
# Create the Gradio interface
|
42 |
with gr.Blocks() as demo:
|
43 |
+
gr.Markdown("# Gemini Prompt Generator")
|
44 |
+
with gr.Tab("Generate Prompt"):
|
45 |
prompt_input = gr.Textbox(label="Your Prompt:", placeholder="Enter your prompt here", lines=5)
|
46 |
+
generate_button = gr.Button("Generate Prompt")
|
47 |
+
output_text = gr.Textbox(label="Generated Prompt:", lines=10, interactive=False)
|
48 |
+
generate_button.click(generate_prompt, inputs=prompt_input, outputs=output_text)
|
49 |
|
50 |
+
# Launch the Gradio application
|
51 |
if __name__ == "__main__":
|
52 |
+
demo.launch()
|