proj_chatbot / app.py
musaashaikh's picture
Update app.py
59f0078 verified
raw
history blame contribute delete
740 Bytes
import gradio as gr
from transformers import pipeline
from utils import retrieve_best_match, setup_faiss_index
# Initialize FAISS index (only runs once)
setup_faiss_index()
# Load Hugging Face model for text generation
generator = pipeline("text-generation", model="tiiuae/falcon-7b-instruct", max_length=150)
# Function to generate a response
def generate_answer(user_query):
best_match = retrieve_best_match(user_query)
prompt = f"Q: {best_match}\nAI:"
response = generator(prompt, max_length=200, do_sample=True)
return response[0]["generated_text"].split("AI:")[-1].strip()
# Create Gradio interface
iface = gr.Interface(fn=generate_answer, inputs="text", outputs="text", title="Physics RAG Chatbot")
iface.launch()