Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # from transformers import pipeline | |
| # from transformers.utils import logging | |
| from llama_index.embeddings.huggingface import HuggingFaceEmbedding | |
| import torch | |
| from llama_index.core import VectorStoreIndex | |
| from llama_index.core import Document | |
| from llama_index.core import Settings | |
| from llama_index.llms.huggingface import ( | |
| HuggingFaceInferenceAPI, | |
| HuggingFaceLLM, | |
| ) | |
| #system_sr = "Zoveš se U-Chat AI asistent i pomažeš korisniku usluga kompanije United Group. Korisnik postavlja pitanje ili problem, upareno sa dodatnima saznanjima. Na osnovu toga napiši korisniku kratak i ljubazan odgovor koji kompletira njegov zahtev ili mu daje odgovor na pitanje. " | |
| # " Ako ne znaš odgovor, reci da ne znaš, ne izmišljaj ga." | |
| #system_sr += "Usluge kompanije United Group uključuju i kablovsku mrežu za digitalnu televiziju, pristup internetu, uređaj EON SMART BOX za TV sadržaj, kao i fiksnu telefoniju." | |
| system_propmpt = "You are a friendly Chatbot." | |
| Settings.llm = HuggingFaceLLM(model_name="facebook/blenderbot-400M-distill", | |
| device_map="cpu", | |
| system_prompt = system_propmpt, | |
| context_window=3900, | |
| tokenizer_kwargs={"max_length": 4096}, | |
| tokenizer_name="facebook/blenderbot-400M-distill" | |
| ) | |
| Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5") | |
| documents = [Document(text="Indian parliament elections happened in April-May 2024. BJP Party won.")] | |
| index = VectorStoreIndex.from_documents( | |
| documents, | |
| ) | |
| query_engine = index.as_query_engine() | |
| def rag(input_text, file): | |
| return query_engine.query( | |
| input_text | |
| ) | |
| iface = gr.Interface(fn=rag, inputs=[gr.Textbox(label="Question", lines=6), gr.File()], | |
| outputs=[gr.Textbox(label="Result", lines=6)], | |
| title="Answer my question", | |
| description= "CoolChatBot" | |
| ) | |
| iface.launch() |