NihalGazi's picture
Create app.py
44afdce verified
raw
history blame
1.21 kB
import os
import google.generativeai as genai
import gradio as gr
# Configure the Gemini API
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
# Define the model with a placeholder for system instruction
def generate_text(system_instruction, prompt):
model = genai.GenerativeModel(
model_name="gemini-1.5-flash",
system_instruction=system_instruction,
generation_config={
"temperature": 1,
"top_p": 0.95,
"top_k": 64,
"max_output_tokens": 8192,
"response_mime_type": "text/plain",
}
)
chat_session = model.start_chat(history=[])
response = chat_session.send_message(prompt)
return response.text
# Gradio interface
iface = gr.Interface(
fn=generate_text,
inputs=[
gr.Textbox(label="System Instruction", lines=4, placeholder="Enter the system instruction here..."),
gr.Textbox(label="Prompt", lines=4, placeholder="Enter the prompt here...")
],
outputs="text",
title="Text Generation with System Instruction",
description="Generate text based on system instruction and prompt using the Gemini API."
)
if __name__ == "__main__":
iface.launch()