Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import google.generativeai as genai
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# Configure the Gemini API
|
6 |
+
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
|
7 |
+
|
8 |
+
# Define the model with a placeholder for system instruction
|
9 |
+
def generate_text(system_instruction, prompt):
|
10 |
+
model = genai.GenerativeModel(
|
11 |
+
model_name="gemini-1.5-flash",
|
12 |
+
system_instruction=system_instruction,
|
13 |
+
generation_config={
|
14 |
+
"temperature": 1,
|
15 |
+
"top_p": 0.95,
|
16 |
+
"top_k": 64,
|
17 |
+
"max_output_tokens": 8192,
|
18 |
+
"response_mime_type": "text/plain",
|
19 |
+
}
|
20 |
+
)
|
21 |
+
|
22 |
+
chat_session = model.start_chat(history=[])
|
23 |
+
response = chat_session.send_message(prompt)
|
24 |
+
|
25 |
+
return response.text
|
26 |
+
|
27 |
+
# Gradio interface
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=generate_text,
|
30 |
+
inputs=[
|
31 |
+
gr.Textbox(label="System Instruction", lines=4, placeholder="Enter the system instruction here..."),
|
32 |
+
gr.Textbox(label="Prompt", lines=4, placeholder="Enter the prompt here...")
|
33 |
+
],
|
34 |
+
outputs="text",
|
35 |
+
title="Text Generation with System Instruction",
|
36 |
+
description="Generate text based on system instruction and prompt using the Gemini API."
|
37 |
+
)
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
iface.launch()
|