Download app.py from Bagda/Guines: direct link, hf CLI and curl.
- Browser
- Download file 1.97 kB
-
https://huggingface.co/spaces/Bagda/Guines/resolve/main/app.py
- Command line
-
hf download hf://spaces/Bagda/Guines/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Bagda/Guines/resolve/main/app.py
1.97 kB
| import gradio as gr | |
| import openai | |
| # OpenAI API Key (यहाँ अपनी API Key डालें) | |
| openai.api_key = "YOUR_API_KEY" | |
| # Backend Function: यूजर का मैसेज लेकर OpenAI से रिस्पॉन्स लाता है | |
| def respond_to_message(message, chat_history): | |
| response = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo", | |
| messages=[{"role": "user", "content": message}] | |
| ) | |
| bot_message = response.choices[0].message['content'] | |
| chat_history.append((message, bot_message)) | |
| return "", chat_history | |
| # Frontend: Gradio UI | |
| with gr.Blocks() as demo: | |
| chatbot = gr.Chatbot(label="AI चैट बोर्ड") | |
| msg = gr.Textbox(label="आपका मैसेज") | |
| clear = gr.ClearButton([msg, chatbot]) | |
| msg.submit(respond_to_message, [msg, chatbot], [msg, chatbot]) | |
| demo.launch() | |
| from datasets import load_dataset | |
| # Login using e.g. `huggingface-cli login` to access this dataset | |
| ds = load_dataset("KadamParth/NCERT_Chemistry_11th") | |
| from transformers import OpenAIGPTTokenizer, TFOpenAIGPTModel | |
| tokenizer = OpenAIGPTTokenizer.from_pretrained("openai-community/openai-gpt") | |
| model = TFOpenAIGPTModel.from_pretrained("openai-community/openai-gpt") | |
| from transformers import OpenAIGPTTokenizer | |
| import pandas as pd | |
| # Dataset load karo (CSV, TXT, etc.) | |
| df = pd.read_csv("your_dataset.csv") # ya pd.read_table("your_dataset.txt", sep="\t") | |
| # Tokenizer load karo (optional, agar similarity check karna hai) | |
| tokenizer = OpenAIGPTTokenizer.from_pretrained("openai-community/openai-gpt") | |
| # Question poochhein | |
| question = "रासायनिक बंध क्या होता है?" | |
| # Simple keyword-based search | |
| def get_answer(question): | |
| for idx, row in df.iterrows(): | |
| if question.lower() in row['question'].lower(): | |
| return row['answer'] | |
| return "जवाब नहीं मिला।" | |
| answer = get_answer(question) | |
| print(answer) | |