Spaces:
Runtime error
Runtime error
File size: 1,128 Bytes
b3b2bb1 e65e361 b3b2bb1 be69a8e be4d498 be69a8e be4d498 f12d3e9 be69a8e be4d498 6336009 be4d498 be69a8e f12d3e9 b3b2bb1 be69a8e |
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 |
import gradio as gr
import pathlib
import textwrap
import google.generativeai as genai
def to_markdown(text):
"""Converts text to Markdown format with proper indentation."""
text = text.replace('•', ' *')
return textwrap.indent(text, '> ', lambda line: True)
def chat(message, history, img=None):
"""Generates a response to the user's message, optionally using an image."""
genai.configure(api_key='AIzaSyCMBk81YmILNTok8hd6tYtJaevp1qbl6I0') # Replace with your actual API key
text_model = genai.GenerativeModel('gemini-pro')
#vision_model = genai.GenerativeModel('gemini-pro-vision')
try:
# Use only text model
response = text_model.generate_content(message, stream=True)
for chunk in response:
return to_markdown(chunk.text) # Format as Markdown
except Exception as e:
print(f"Error during generation: {e}")
return "An error occurred while generating the response. Please try again later."
chat_interface = gr.ChatInterface(
fn=chat,
title="Gemini Chat",
description="Chat with an AI assistant powered by Gemini",
theme="soft"
)
chat_interface.launch()
|