Upload 3 files
Browse files- app.py +30 -0
- data/handshape_book.txt +0 -0
- requirements.txt +10 -0
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from sentence_transformers import SentenceTransformer, util
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Load data
|
| 6 |
+
with open("data/handshape_book.txt", encoding="utf-8") as f:
|
| 7 |
+
book_text = f.read()
|
| 8 |
+
|
| 9 |
+
# Split into chunks
|
| 10 |
+
chunks = [chunk.strip() for chunk in book_text.split('\n\n') if len(chunk.strip()) > 100]
|
| 11 |
+
|
| 12 |
+
# Create embeddings
|
| 13 |
+
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
|
| 14 |
+
corpus_embeddings = model.encode(chunks, convert_to_tensor=True)
|
| 15 |
+
|
| 16 |
+
# Search function
|
| 17 |
+
def ask_question(question):
|
| 18 |
+
question_embedding = model.encode(question, convert_to_tensor=True)
|
| 19 |
+
hits = util.semantic_search(question_embedding, corpus_embeddings, top_k=3)[0]
|
| 20 |
+
results = "\n\n---\n\n".join([chunks[hit['corpus_id']] for hit in hits])
|
| 21 |
+
return results
|
| 22 |
+
|
| 23 |
+
# Gradio UI
|
| 24 |
+
iface = gr.Interface(fn=ask_question,
|
| 25 |
+
inputs=gr.Textbox(lines=2, placeholder="Ask about handshapes..."),
|
| 26 |
+
outputs="text",
|
| 27 |
+
title="ASL Handshape RAG",
|
| 28 |
+
description="Semantic search over American Sign Language Handshape Dictionary.")
|
| 29 |
+
|
| 30 |
+
iface.launch()
|
data/handshape_book.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers>=4.39.3
|
| 2 |
+
sentence-transformers>=2.7.0
|
| 3 |
+
faiss-cpu>=1.7.4
|
| 4 |
+
gradio>=5.0.0
|
| 5 |
+
python-multipart
|
| 6 |
+
pydub
|
| 7 |
+
orjson
|
| 8 |
+
pdfplumber>=0.10.0
|
| 9 |
+
fastapi>=0.115.2
|
| 10 |
+
uvicorn>=0.34.0
|