Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,13 +3,52 @@ import os
|
|
| 3 |
from google.generativeai as genai
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
import fitz
|
|
|
|
| 6 |
|
| 7 |
load_dotenv()
|
| 8 |
|
| 9 |
GEMINI_API_KEY = os.environ["GEMINI_API_KEY"]
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
st.title("Gemini chatbot")
|
| 12 |
st.subheader("Hola, hazle una pregunta a Gemini :)")
|
| 13 |
|
| 14 |
prompt = st.text_input("Escribe tu prompt aquí")
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from google.generativeai as genai
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
import fitz
|
| 6 |
+
import base64
|
| 7 |
|
| 8 |
load_dotenv()
|
| 9 |
|
| 10 |
GEMINI_API_KEY = os.environ["GEMINI_API_KEY"]
|
| 11 |
|
| 12 |
+
|
| 13 |
+
def generate():
|
| 14 |
+
client = genai.Client(
|
| 15 |
+
api_key=os.environ.get("GEMINI_API_KEY"),
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
model = "gemini-2.5-pro-exp-03-25"
|
| 19 |
+
contents = [
|
| 20 |
+
types.Content(
|
| 21 |
+
role="user",
|
| 22 |
+
parts=[
|
| 23 |
+
types.Part.from_text(text="""INSERT_INPUT_HERE"""),
|
| 24 |
+
],
|
| 25 |
+
),
|
| 26 |
+
]
|
| 27 |
+
generate_content_config = types.GenerateContentConfig(
|
| 28 |
+
temperature=1,
|
| 29 |
+
top_p=0.95,
|
| 30 |
+
top_k=64,
|
| 31 |
+
max_output_tokens=65536,
|
| 32 |
+
response_mime_type="text/plain",
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
for chunk in client.models.generate_content_stream(
|
| 36 |
+
model=model,
|
| 37 |
+
contents=contents,
|
| 38 |
+
config=generate_content_config,
|
| 39 |
+
):
|
| 40 |
+
print(chunk.text, end="")
|
| 41 |
+
|
| 42 |
+
if __name__ == "__main__":
|
| 43 |
+
generate()
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
|
| 47 |
st.title("Gemini chatbot")
|
| 48 |
st.subheader("Hola, hazle una pregunta a Gemini :)")
|
| 49 |
|
| 50 |
prompt = st.text_input("Escribe tu prompt aquí")
|
| 51 |
+
|
| 52 |
+
if prompt:
|
| 53 |
+
response = model.generate(prompt)
|
| 54 |
+
st.write(response.text)
|