Spaces:
Sleeping
Sleeping
Download app.py from wasmdashai/T2T2: direct link, hf CLI and curl.
- Browser
- Download file 1.59 kB
-
https://huggingface.co/spaces/wasmdashai/T2T2/resolve/main/app.py
- Command line
-
hf download hf://spaces/wasmdashai/T2T2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/wasmdashai/T2T2/resolve/main/app.py
1.59 kB
| import gradio as gr | |
| import os | |
| import google.generativeai as genai | |
| generation_config = { | |
| "temperature": 1, | |
| "top_p": 0.95, | |
| "top_k": 40, | |
| "max_output_tokens": 8192, | |
| "response_mime_type": "text/plain", | |
| } | |
| def create_chat_session(): | |
| chat_session = Model.start_chat( | |
| history=[ | |
| { | |
| "role": "user", | |
| "parts": [ | |
| "دائما اجابتك بالعربية تكون باللهجة النجدية السلام عليكم كيف الحال\n", | |
| ], | |
| }, | |
| { | |
| "role": "model", | |
| "parts": [ | |
| " ابشر سم ما عليك امر وعليكم السلام ورحمة الله وبركاته. بخير، والحال معك؟\n", | |
| ], | |
| }, | |
| ] | |
| ) | |
| return chat_session | |
| def get_answer_ai(text): | |
| global AI | |
| try: | |
| response = AI.send_message(text) | |
| return response.text | |
| except : | |
| AI=create_chat_session() | |
| response = AI.send_message(text) | |
| return response.text | |
| AI=None | |
| Model=None | |
| isActive=""; | |
| def greet(text,key): | |
| global isActive | |
| global Model | |
| global AI | |
| if key!="": | |
| genai.configure(api_key=key) | |
| Model = genai.GenerativeModel( | |
| model_name="gemini-1.5-flash-8b", | |
| generation_config=generation_config, | |
| ) | |
| isActive=key | |
| AI=create_chat_session() | |
| return get_answer_ai(text) | |
| demo = gr.Interface(fn=greet, inputs=["text","text"], outputs="text") | |
| demo.launch() | |