persadian commited on
Commit
22b550c
·
verified ·
1 Parent(s): 5062bb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -39
app.py CHANGED
@@ -1,44 +1,17 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForCausalLM
3
- import torch
4
 
5
- # Load model and tokenizer
6
- model_name = "persadian/CropSeek-LLM"
7
- tokenizer = AutoTokenizer.from_pretrained(model_name)
8
- model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype=torch.float16)
9
 
10
- # Native inference function
11
- def cropseek_response(prompt):
12
- inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
13
- outputs = model.generate(
14
- **inputs,
15
- max_new_tokens=300,
16
- do_sample=True,
17
- temperature=0.7,
18
- top_p=0.95,
19
- repetition_penalty=1.2,
20
- )
21
- return tokenizer.decode(outputs[0], skip_special_tokens=True)
22
 
23
- # External embed
24
- def embed_external():
25
- return """<iframe src="https://cropseek-llm.netlify.app/" width="100%" height="800px" style="border:none;"></iframe>"""
26
 
27
- # Gradio Tabs layout
28
- with gr.Blocks(title="CropSeek-LLM") as demo:
29
- gr.Markdown("# 🌿 CropSeek-LLM\nYour AI partner for crop planning, pest control, and soil optimization.")
30
-
31
- with gr.Tab("🧠 Ask the Model"):
32
- gr.Markdown("### Ask CropSeek-LLM a question:")
33
- with gr.Row():
34
- prompt = gr.Textbox(label="Your Question", lines=4, placeholder="e.g. Best time to plant tomatoes in Limpopo?")
35
- output = gr.Textbox(label="Model Response")
36
- ask_button = gr.Button("Submit")
37
- ask_button.click(fn=cropseek_response, inputs=prompt, outputs=output)
38
-
39
- with gr.Tab("🌐 External Dashboard"):
40
- gr.HTML(embed_external())
41
-
42
- # Launch app
43
- if __name__ == "__main__":
44
- demo.launch()
 
1
  import gradio as gr
 
 
2
 
3
+ def embed_cropseek():
4
+ return """
5
+ <iframe src="https://cropseek-llm.netlify.app/" width="100%" height="800px" style="border:none;"></iframe>
6
+ """
7
 
8
+ iface = gr.Interface(
9
+ fn=embed_cropseek,
10
+ inputs=[],
11
+ outputs=gr.HTML(),
12
+ title="CropSeek-LLM (DARJYO)",
13
+ live=True,
14
+ )
 
 
 
 
 
15
 
16
+ iface.launch()
 
 
17