File: //opt/multimodal/app.py
import streamlit as st
import requests
import json
import time
from streamlit_webrtc import webrtc_streamer
def main():
st.title("Gemini 2.0 Multimodal App")
# Authentication
code = st.text_input("Enter Code")
if code:
# Load system prompt based on code
if code == "prompt1":
system_prompt = "You are a helpful assistant. Answer questions in a clear and concise way."
elif code == "prompt2":
system_prompt = "You are a creative writer. Write a poem about a lonely cloud."
else:
system_prompt = "Invalid code. Please try again."
if system_prompt != "Invalid code. Please try again.":
# Initialize Gemini API session
url = "https://api.gemini.google.com/v1/models/gemini-2.0-multimodal-live:generate"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
# Streamlit WebRTC for video/audio input
webrtc_ctx = webrtc_streamer(
key="example",
video_processor_factory=VideoProcessor,
audio_processor_factory=AudioProcessor,
)
if webrtc_ctx.state.playing:
# Send prompt and media to Gemini API
data = {
"inputs": {
"text": system_prompt,
"audio": webrtc_ctx.state.audio,
"video": webrtc_ctx.state.video
},
"temperature": 0.7
}
response = requests.post(url, headers=headers, json=data, stream=True)
for line in response.iter_lines():
if line:
decoded_line = line.decode('utf-8')
st.write(decoded_line)
time.sleep(0.5) # Adjust delay as needed
class VideoProcessor:
def recv(self, frame):
# Process video frame if needed
return frame
class AudioProcessor:
def recv(self, frame):
# Process audio frame if needed
return frame
if __name__ == '__main__':
main()