ocr / app.py
Atchyuteswar's picture
Upload 7 files
f347e77 verified
raw
history blame contribute delete
No virus
1.68 kB
import google.generativeai as genai
import gradio as gr
import os
generation_config = {
"temperature": 0,
"top_p": 1,
"top_k": 32,
"max_output_token": 4096,
}
safety_settings = [
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
]
genai.configure(api_key="AIzaSyAEinSmbNfJHdThXN2nA3Oxf82Qb7zQsLo")
model = genai.GenerativeModel(model_name="gemini-pro-vision",
generation_config=generation_config,
safety_settings=safety_settings)
import_prompt = """ """
def upload_file(files, text_input):
file_paths = [file.name for file in files]
if file_paths:
response = generate_gemini_response(input_prompt, text_input, file_paths[0])
return file_paths[0], response
with gr.Blocks() as demo:
header = gr.Label("Please let us know about your injury and Gen AI will try to help you")
text_input = gr.Textbox(label="Explain a bit more about your injury")
image_output = gr.Image()
upload_button = gr.UploadButton("Upload an image",
file_type=["image"],
file_count="multiple")
file_output = gr.Textbox(label="First-aid process")
combined_output = [image_output, file_output]
upload_button.upload(upload_file, [upload_button, text_input], combined_output)
demo.launch(debug=True)