Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
from fastapi.middleware.cors import CORSMiddleware
|
| 2 |
from fastapi import FastAPI, Request, Header, BackgroundTasks, HTTPException, status
|
| 3 |
-
import google.generativeai as genai
|
| 4 |
-
|
| 5 |
import json
|
| 6 |
import os
|
| 7 |
|
|
@@ -15,10 +15,16 @@ from linebot.models import (
|
|
| 15 |
MessageEvent, TextMessage, TextSendMessage, ImageSendMessage, AudioMessage
|
| 16 |
)
|
| 17 |
|
| 18 |
-
GOOGLE_API_KEY = os.environ["GOOGLE_API_KEY"]
|
| 19 |
-
genai.configure(api_key = GOOGLE_API_KEY)
|
| 20 |
-
# Initialize the Gemini model
|
| 21 |
-
model = genai.GenerativeModel('gemini-pro')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
app = FastAPI()
|
| 24 |
app.add_middleware(
|
|
@@ -75,11 +81,15 @@ def handle_message(event):
|
|
| 75 |
"role": "user",
|
| 76 |
"parts": [message],
|
| 77 |
})
|
| 78 |
-
|
| 79 |
-
response = model.generate_content(messages)
|
| 80 |
-
out = response.parts[0].text
|
| 81 |
# Check if response is valid
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
out = "Gemini: [No response or the response does not contain text]"
|
| 84 |
except:
|
| 85 |
out = "Gemini error!"
|
|
|
|
| 1 |
from fastapi.middleware.cors import CORSMiddleware
|
| 2 |
from fastapi import FastAPI, Request, Header, BackgroundTasks, HTTPException, status
|
| 3 |
+
# import google.generativeai as genai
|
| 4 |
+
from gradio_client import Client
|
| 5 |
import json
|
| 6 |
import os
|
| 7 |
|
|
|
|
| 15 |
MessageEvent, TextMessage, TextSendMessage, ImageSendMessage, AudioMessage
|
| 16 |
)
|
| 17 |
|
| 18 |
+
# GOOGLE_API_KEY = os.environ["GOOGLE_API_KEY"]
|
| 19 |
+
# genai.configure(api_key = GOOGLE_API_KEY)
|
| 20 |
+
# # Initialize the Gemini model
|
| 21 |
+
# model = genai.GenerativeModel('gemini-pro')
|
| 22 |
+
|
| 23 |
+
client = Client("https://alanchen1115-gemini-api.hf.space/--replicas/mgfss/")
|
| 24 |
+
result = client.predict(
|
| 25 |
+
"Hello!!", # str in 'Prompt' Textbox component
|
| 26 |
+
api_name="/predict"
|
| 27 |
+
)
|
| 28 |
|
| 29 |
app = FastAPI()
|
| 30 |
app.add_middleware(
|
|
|
|
| 81 |
"role": "user",
|
| 82 |
"parts": [message],
|
| 83 |
})
|
|
|
|
|
|
|
|
|
|
| 84 |
# Check if response is valid
|
| 85 |
+
|
| 86 |
+
# response = model.generate_content(messages)
|
| 87 |
+
# out = response.parts[0].text
|
| 88 |
+
# if not response.parts or not response.parts[0].text:
|
| 89 |
+
# out = response.parts[0].text
|
| 90 |
+
|
| 91 |
+
out = client.predict(messages, api_name="/predict")
|
| 92 |
+
if not out:
|
| 93 |
out = "Gemini: [No response or the response does not contain text]"
|
| 94 |
except:
|
| 95 |
out = "Gemini error!"
|