george sami
e
1b85f14
from transformers import pipeline
import gradio as gr
import os
# Initialize the question-answering pipeline
def initialize_pipeline():
model_name = "deepset/roberta-base-squad2" # Example question-answering model
try:
qa_pipeline = pipeline("question-answering", model=model_name)
return qa_pipeline
except Exception as e:
print(f"Error initializing the pipeline: {e}")
return None
qa_pipeline = initialize_pipeline()
# Define your custom context
custom_context = """
George sami is a well known technical lead who can work on frontend, backend, mobile and ai development.
he started his career on 2019. have a good problem solving skills and technical. he was born in december 1995
"""
def query_with_context(question):
"""Queries the QA model with context and a question."""
if qa_pipeline is None:
return "Error: Pipeline not initialized."
try:
result = qa_pipeline(context=custom_context, question=question)
return result['answer']
except Exception as e:
return f"Error during inference: {e}"
if __name__ == "__main__":
if qa_pipeline is not None:
interface = gr.Interface(
fn=query_with_context,
inputs=gr.Textbox(label="Your Question"),
outputs=gr.Textbox(label="AI Response"),
title="Custom Context AI",
description="Ask me anything about George Sami"
)
interface.launch()
else:
print("Application could not start due to pipeline error.")