ShebMichel's picture
Update app.py
472db8f verified
raw
history blame
3.75 kB
import gradio as gr
import os
os.environ["KERAS_BACKEND"] = "tensorflow"
import keras
import keras_nlp
css = """
html, body {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
}
body::before {
content: '';
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-image: url('https://github.com/ShebMichel/kagglex_imagebot/blob/main/geoBot_to_github.gif');
background-size: cover;
background-repeat: no-repeat;
opacity: 0.65; /* Faint background image */
background-position: center;
z-index: -1; /* Keep the background behind text */
}
.gradio-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh; /* Ensure the content is vertically centered */
}
"""
geomodel_llm = keras_nlp.models.CausalLM.from_preset("hf://ShebMichel/geobot_teacher-v0")
def launch(input):
template = "Instruction:\n{instruction}\n\nResponse:\n{response}"
prompt = template.format(
instruction=input,
response="",
)
out = geomodel_llm.generate(prompt, max_length=1024)
ind = out.index('Response') + len('Response')+2
return out[ind:]
# Define the function to handle both text and file input
def analyze_response(text_input, file_input):
# Process text and file inputs as required
# For now, we'll just return a placeholder response
response = f"Received text: {text_input}\n"
if file_input is not None:
response += f"File uploaded: {file_input.name}"
else:
response += "No file uploaded."
return response
# Set up Gradio Interface
# iface = gr.Interface(
# #fn=chatbot,
# inputs=[
# gr.File(label="Upload a file (PDF, JSON, DOCX)"),
# gr.Textbox(label="Your Message"),
# "state" # Keeps chat history between turns
# ],
# outputs="chatbot",
# live=True,
# description="Drag and drop a file and start chatting with the bot based on its contents."
# )
# iface.launch()
#title="πŸ‘‹ Hola-Hello-Bonjour-Mbote-δ½ ε₯½ πŸ‘‹ <br><br> I am geobot-teacher the student marker! <br><br> I am here to analyse each question to determine whether the response qualifies as a pass or fail. <br><br> Try me :)",
#description="Synthetic QA pairs (~1k) was finetuned on top of Gemma_2b_en.")
# inputs="text"
# iface = gr.Interface(launch,
# inputs="text",
# outputs="text",
# css=css,
# title="πŸ‘‹ Hi, I am geobot-teacher: The Student Marker πŸ‘‹",
# description="Hola/Hello/Bonjour/Mbote/δ½ ε₯½ \n\n"
# "I am here to analyse each question to determine whether the response qualifies as a pass or fail.\n\n"
# "Try me :)",
# )
iface = gr.Interface(fn=analyze_response,
inputs=[
gr.File(label="Upload a file (PDF, JSON, DOCX)"),gr.Textbox(label="Enter your response"), gr.Radio(
["QCM","short_answer_questions","long_answer_questions"])],
outputs="text",
css=css,
title="πŸ‘‹ Hi, I am geobot-teacher: The Student Marker πŸ‘‹",
description="Hola/Hello/Bonjour/Mbote/δ½ ε₯½ \n\n"
"I am here to analyse each question to determine whether the response qualifies as a pass or fail.\n\n"
"Try me :)",
)
iface.launch(share=True)