Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,62 +1,47 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
-
from
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
)
|
| 14 |
|
| 15 |
-
def
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
return "Web search unavailable."
|
| 27 |
-
|
| 28 |
-
def inachi_ai_response(user_input, history):
|
| 29 |
-
context = web_search(user_input)
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
]
|
| 35 |
|
| 36 |
-
|
| 37 |
-
try:
|
| 38 |
-
# 🔱 මෙතනදී තමයි Model එක සහ Provider එක සෘජුවම සම්බන්ධ කරන්නේ
|
| 39 |
-
# උදා: Novita පාවිච්චි කිරීමට 'provider="novita"' ලෙස එක් කරන්න
|
| 40 |
-
for message in client.chat_completion(
|
| 41 |
-
model="google/gemma-4-E2B",
|
| 42 |
-
messages=messages,
|
| 43 |
-
max_tokens=1024,
|
| 44 |
-
stream=True,
|
| 45 |
-
# provider="novita" # <--- ඔන්න මෙතනට Provider දාන්න පුළුවන්
|
| 46 |
-
):
|
| 47 |
-
token = message.choices[0].delta.content
|
| 48 |
-
if token:
|
| 49 |
-
response += token
|
| 50 |
-
yield response
|
| 51 |
-
except Exception as e:
|
| 52 |
-
yield f"Error Specialist: {str(e)}"
|
| 53 |
|
| 54 |
-
# 🔱
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
| 62 |
demo.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import pipeline
|
| 4 |
|
| 5 |
+
# Model configuration
|
| 6 |
+
# Note: Use "google/gemma-2-2b-it" as it is highly efficient for Free Tier Spaces
|
| 7 |
+
model_id = "google/gemma-2-2b-it"
|
| 8 |
|
| 9 |
+
# Specialist Inference Engine initialization
|
| 10 |
+
pipe = pipeline(
|
| 11 |
+
"text-generation",
|
| 12 |
+
model=model_id,
|
| 13 |
+
model_kwargs={"torch_dtype": torch.bfloat16},
|
| 14 |
+
device_map="auto",
|
| 15 |
)
|
| 16 |
|
| 17 |
+
def specialist_respond(message, history):
|
| 18 |
+
# System prompt to maintain identity
|
| 19 |
+
system_prompt = "You are a highly advanced AI assistant developed under the INACHI AI project. Be precise and technical."
|
| 20 |
+
|
| 21 |
+
# Building the conversation format for Gemma
|
| 22 |
+
messages = [{"role": "system", "content": system_prompt}]
|
| 23 |
+
for val in history:
|
| 24 |
+
if val[0]: messages.append({"role": "user", "content": val[0]})
|
| 25 |
+
if val[1]: messages.append({"role": "assistant", "content": val[1]})
|
| 26 |
+
|
| 27 |
+
messages.append({"role": "user", "content": message})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
# Generating the response
|
| 30 |
+
prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 31 |
+
outputs = pipe(prompt, max_new_tokens=512, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
|
|
|
| 32 |
|
| 33 |
+
return outputs[0]["generated_text"][len(prompt):]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
# 🔱 INACHI AI UI Design
|
| 36 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 37 |
+
gr.Markdown("""# 🔱 INACHI AI: SPECIALIST INTERFACE
|
| 38 |
+
### Powered by Gemma 2B | Authorized Access: MINZO-PRIME""")
|
| 39 |
+
|
| 40 |
+
chatbot = gr.ChatInterface(
|
| 41 |
+
fn=specialist_respond,
|
| 42 |
+
title="INACHI-GEMMA V1",
|
| 43 |
+
description="Advanced neural processing unit for system research and development.",
|
| 44 |
+
)
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
| 47 |
demo.launch()
|