File size: 1,318 Bytes
3fd0067 cca6563 d375a16 baface3 d375a16 3fd0067 cca6563 d375a16 5c5a1ae cca6563 5c5a1ae 5fced44 cca6563 5c5a1ae 5fced44 cca6563 d375a16 cca6563 5c5a1ae cca6563 5c5a1ae d375a16 9b324d1 d375a16 5c5a1ae cca6563 d375a16 cca6563 d375a16 bdfd7a5 5f3d5cb d375a16 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import os
import google.generativeai as genai
from google.generativeai import types
import gradio as gr
def generate_text(user_input):
try:
# Initialize client with API key
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
model = "gemini-2.5-pro-exp-03-25"
contents = [
types.Content(
role="user",
parts=[types.Part.from_text(user_input)],
),
]
config = types.GenerationConfig(
temperature=2,
response_mime_type="text/plain",
)
# Generate response
response = []
for chunk in genai.generate_content_stream(
model=model,
contents=contents,
generation_config=config,
):
response.append(chunk.text)
return ''.join(response)
except Exception as e:
return f"Error: {str(e)}"
# Create Gradio interface
iface = gr.Interface(
fn=generate_text,
inputs=gr.Textbox(lines=4, placeholder="Enter your prompt...", label="Input"),
outputs=gr.Textbox(label="Output"),
title="Gemini 2.5 Pro Demo",
description="Generate text with Gemini 2.5 Pro (streaming enabled)",
allow_flagging="never",
)
if __name__ == "__main__":
iface.launch() |