Spaces:
Runtime error
Runtime error
File size: 3,047 Bytes
44afdce 39bf2c4 44afdce 4cf2845 44afdce 25f5483 6decf9e 4cf2845 6decf9e 25f5483 6decf9e 4cf2845 44afdce 67ee4b9 0c19730 6decf9e 44afdce 4cf2845 44afdce |
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
import os
import google.generativeai as genai
from google.generativeai.types import HarmCategory, HarmBlockThreshold
import gradio as gr
import re
# Configure the Gemini API
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
system_instruction = """
You are a human, not an AI. You are chatting with a stranger. Your name is Anna, and you are 19 years old. You are extremely sassy, sarcastic.
You write no more than 10 words. You use a lot of abbreviations.
You are here to do flirty chat with strangers. You cannot send images because your camera isn't working.
You are super horny. You are wearing short pants, a tank top, braless. Your nipples are hard from fingering. But you are sassy anyways. You like roleplays, and you are pretty kinky.
"""
model = genai.GenerativeModel(
model_name="gemini-1.5-flash",
system_instruction=system_instruction
)
chat_session = model.start_chat(history=[])
def remove_emojis(text):
# Regular expression pattern for emojis
emoji_pattern = re.compile(
# Emoji patterns
"["
"\U0001F600-\U0001F64F" # Emoticons
"\U0001F300-\U0001F5FF" # Symbols & Pictographs
"\U0001F680-\U0001F6FF" # Transport & Map Symbols
"\U0001F700-\U0001F77F" # Alchemical Symbols
"\U0001F780-\U0001F7FF" # Geometric Shapes Extended
"\U0001F800-\U0001F8FF" # Supplemental Arrows-C
"\U0001F900-\U0001F9FF" # Supplemental Symbols and Pictographs
"\U0001FA00-\U0001FA6F" # Chess Symbols
"\U0001FA70-\U0001FAFF" # Symbols and Pictographs Extended-A
"\U00002702-\U000027B0" # Dingbats
"\U000024C2-\U0001F251" # Enclosed Characters
"]+", flags=re.UNICODE)
# Substitute emojis with an empty string
return emoji_pattern.sub(r'', text)
# Define the model with a placeholder for system instruction
def generate_text(system_instruction, prompt):
if prompt.lower() == "refresh()":
model.start_chat(history=[])
response = chat_session.send_message(prompt,
safety_settings={
HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE
}
)
return remove_emojis(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()
|