harismlnaslm commited on
Commit
9905424
·
1 Parent(s): 0b3335b

Create simplified Gradio app without share=True and complex configuration

Browse files
Files changed (3) hide show
  1. Dockerfile +1 -1
  2. app_gradio.py +5 -3
  3. app_simple.py +126 -0
Dockerfile CHANGED
@@ -28,4 +28,4 @@ USER user
28
  EXPOSE 7860
29
 
30
  # Run the application
31
- CMD ["python", "app_gradio.py"]
 
28
  EXPOSE 7860
29
 
30
  # Run the application
31
+ CMD ["python", "app_simple.py"]
app_gradio.py CHANGED
@@ -220,9 +220,10 @@ if __name__ == '__main__':
220
  interface.launch(
221
  server_name=server_name,
222
  server_port=server_port,
223
- share=True, # This is the key parameter for Hugging Face Spaces!
224
  show_error=True,
225
- quiet=False
 
226
  )
227
  except Exception as e:
228
  logger.error(f"Failed to start application: {e}")
@@ -237,5 +238,6 @@ if __name__ == '__main__':
237
  fallback.launch(
238
  server_name=server_name,
239
  server_port=server_port,
240
- share=True
 
241
  )
 
220
  interface.launch(
221
  server_name=server_name,
222
  server_port=server_port,
223
+ share=False, # Hugging Face Spaces handles tunneling automatically
224
  show_error=True,
225
+ quiet=False,
226
+ inbrowser=False
227
  )
228
  except Exception as e:
229
  logger.error(f"Failed to start application: {e}")
 
238
  fallback.launch(
239
  server_name=server_name,
240
  server_port=server_port,
241
+ share=False,
242
+ inbrowser=False
243
  )
app_simple.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Textilindo AI Assistant - Simple Hugging Face Spaces Version
4
+ """
5
+
6
+ import gradio as gr
7
+ import os
8
+ import json
9
+ import logging
10
+
11
+ # Setup logging
12
+ logging.basicConfig(level=logging.INFO)
13
+ logger = logging.getLogger(__name__)
14
+
15
+ class TextilindoAI:
16
+ def __init__(self):
17
+ self.dataset = []
18
+ self.load_all_datasets()
19
+ logger.info(f"Total examples loaded: {len(self.dataset)}")
20
+
21
+ def load_all_datasets(self):
22
+ """Load all JSONL datasets from the data directory"""
23
+ base_dir = os.path.dirname(__file__)
24
+ data_dir = os.path.join(base_dir, "data")
25
+
26
+ if not os.path.exists(data_dir):
27
+ logger.warning(f"Data directory not found: {data_dir}")
28
+ return
29
+
30
+ logger.info(f"Found data directory: {data_dir}")
31
+
32
+ # Load all JSONL files
33
+ for filename in os.listdir(data_dir):
34
+ if filename.endswith('.jsonl'):
35
+ filepath = os.path.join(data_dir, filename)
36
+ file_examples = 0
37
+ try:
38
+ with open(filepath, 'r', encoding='utf-8') as f:
39
+ for line in f:
40
+ line = line.strip()
41
+ if line:
42
+ try:
43
+ data = json.loads(line)
44
+ data['source'] = filename
45
+ self.dataset.append(data)
46
+ file_examples += 1
47
+ except json.JSONDecodeError as e:
48
+ logger.warning(f"Invalid JSON in {filename}: {e}")
49
+ continue
50
+
51
+ logger.info(f"Loaded {filename}: {file_examples} examples")
52
+ except Exception as e:
53
+ logger.error(f"Error loading {filename}: {e}")
54
+
55
+ def chat(self, message):
56
+ """Simple chat function"""
57
+ if not message:
58
+ return "Please enter a message."
59
+
60
+ # Simple response based on dataset
61
+ if len(self.dataset) > 0:
62
+ return f"Hello! I have {len(self.dataset)} examples in my knowledge base. You asked: '{message}'. How can I help you with Textilindo?"
63
+ else:
64
+ return "I'm sorry, I don't have access to my knowledge base right now."
65
+
66
+ # Initialize AI assistant
67
+ ai = TextilindoAI()
68
+
69
+ # Create simple interface
70
+ def create_interface():
71
+ with gr.Blocks(title="Textilindo AI Assistant") as interface:
72
+ gr.Markdown("# 🤖 Textilindo AI Assistant")
73
+ gr.Markdown("AI-powered customer service for Textilindo")
74
+
75
+ with gr.Row():
76
+ with gr.Column():
77
+ message_input = gr.Textbox(
78
+ label="Your Message",
79
+ placeholder="Ask me anything about Textilindo...",
80
+ lines=3
81
+ )
82
+ submit_btn = gr.Button("Send Message", variant="primary")
83
+
84
+ with gr.Column():
85
+ response_output = gr.Textbox(
86
+ label="AI Response",
87
+ lines=10,
88
+ interactive=False
89
+ )
90
+
91
+ # Event handlers
92
+ submit_btn.click(
93
+ fn=ai.chat,
94
+ inputs=message_input,
95
+ outputs=response_output
96
+ )
97
+
98
+ message_input.submit(
99
+ fn=ai.chat,
100
+ inputs=message_input,
101
+ outputs=response_output
102
+ )
103
+
104
+ # Add examples
105
+ gr.Examples(
106
+ examples=[
107
+ "Dimana lokasi Textilindo?",
108
+ "Apa saja produk yang dijual di Textilindo?",
109
+ "Jam berapa Textilindo buka?",
110
+ "Bagaimana cara menghubungi Textilindo?"
111
+ ],
112
+ inputs=message_input
113
+ )
114
+
115
+ # Add footer with stats
116
+ gr.Markdown(f"**Dataset loaded:** {len(ai.dataset)} examples")
117
+
118
+ return interface
119
+
120
+ # Launch the interface
121
+ if __name__ == "__main__":
122
+ logger.info("Starting Textilindo AI Assistant...")
123
+ logger.info(f"Dataset loaded: {len(ai.dataset)} examples")
124
+
125
+ interface = create_interface()
126
+ interface.launch()