NoufSaleh46 commited on
Commit
c7353aa
·
verified ·
1 Parent(s): 954619d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -6
app.py CHANGED
@@ -3,7 +3,6 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3
  import torch
4
  import spaces
5
 
6
-
7
  def get_model_name(language):
8
  """Map language choice to the corresponding model."""
9
  model_mapping = {
@@ -30,6 +29,7 @@ def load_model(model_name):
30
  do_sample=False
31
  )
32
  return generator
 
33
  @spaces.GPU
34
  def generate_plant_info(plant_name, language):
35
  model_name = get_model_name(language)
@@ -49,16 +49,15 @@ def generate_plant_info(plant_name, language):
49
  output = generator(messages)
50
  return output[0]["generated_text"]
51
 
52
-
53
- # Create Gradio interface
54
  demo = gr.Interface(
55
  fn=generate_plant_info,
56
  inputs=[
57
  gr.Textbox(placeholder="Enter plant name (e.g., Lavender, Aloe Vera)...", label="Plant Name"),
58
  gr.Dropdown(
59
- choices=["English", "Arabic"], # Users choose the language, not the model name
60
  label="Choose Language",
61
- value="English" # Default to English
62
  )
63
  ],
64
  outputs=gr.Textbox(label="Plant Information"),
@@ -71,6 +70,29 @@ demo = gr.Interface(
71
  ["الصبار", "Arabic"]
72
  ],
73
  theme="default",
 
74
  )
75
 
76
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  import torch
4
  import spaces
5
 
 
6
  def get_model_name(language):
7
  """Map language choice to the corresponding model."""
8
  model_mapping = {
 
29
  do_sample=False
30
  )
31
  return generator
32
+
33
  @spaces.GPU
34
  def generate_plant_info(plant_name, language):
35
  model_name = get_model_name(language)
 
49
  output = generator(messages)
50
  return output[0]["generated_text"]
51
 
52
+ # Create Gradio interface with enhancements
 
53
  demo = gr.Interface(
54
  fn=generate_plant_info,
55
  inputs=[
56
  gr.Textbox(placeholder="Enter plant name (e.g., Lavender, Aloe Vera)...", label="Plant Name"),
57
  gr.Dropdown(
58
+ choices=["English", "Arabic"],
59
  label="Choose Language",
60
+ value="English"
61
  )
62
  ],
63
  outputs=gr.Textbox(label="Plant Information"),
 
70
  ["الصبار", "Arabic"]
71
  ],
72
  theme="default",
73
+ layout="vertical", # Change layout for better organization
74
  )
75
 
76
+ # Custom CSS for styling
77
+ custom_css = """
78
+ <style>
79
+ body {
80
+ font-family: Arial, sans-serif;
81
+ background-color: #f9f9f9;
82
+ }
83
+ .gri-container {
84
+ border-radius: 10px;
85
+ background-color: #fff;
86
+ box-shadow: 0 4px 20px rgba(0,0,0,0.1);
87
+ }
88
+ .gri-button {
89
+ background-color: #4CAF50;
90
+ color: white;
91
+ }
92
+ .gri-button:hover {
93
+ background-color: #45a049;
94
+ }
95
+ </style>
96
+ """
97
+
98
+ demo.launch(share=True, css=custom_css) # Launch the interface with custom CSS