Rajesh Karra commited on
Commit
e49526f
·
1 Parent(s): cb253c4
Files changed (2) hide show
  1. app.py +40 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ # Replace this with your actual Gemini 2.0 API key
5
+ GEMINI_API_KEY = "your_gemini_api_key_here"
6
+
7
+ def query_gemini(prompt):
8
+ url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent"
9
+ headers = {
10
+ "Content-Type": "application/json"
11
+ }
12
+ params = {
13
+ "key": GEMINI_API_KEY
14
+ }
15
+ data = {
16
+ "contents": [
17
+ {
18
+ "parts": [
19
+ {"text": prompt}
20
+ ]
21
+ }
22
+ ]
23
+ }
24
+ response = requests.post(url, headers=headers, params=params, json=data)
25
+
26
+ try:
27
+ return response.json()['candidates'][0]['content']['parts'][0]['text']
28
+ except Exception as e:
29
+ return f"Error: {e}\nResponse: {response.text}"
30
+
31
+ iface = gr.Interface(
32
+ fn=query_gemini,
33
+ inputs=gr.Textbox(lines=4, placeholder="Ask something..."),
34
+ outputs="text",
35
+ title="Gemini 2.0 API with Gradio",
36
+ description="A simple Hugging Face Space using Gemini 2.0 Flash API"
37
+ )
38
+
39
+ if __name__ == "__main__":
40
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ requests