Spaces:
Running
Running
Create app.py
Browse files
app.py
CHANGED
@@ -1,126 +1,138 @@
|
|
1 |
import gradio as gr
|
2 |
-
import torch
|
3 |
-
import gc
|
4 |
-
from diffusers import StableDiffusionInpaintPipeline
|
5 |
-
from PIL import Image
|
6 |
-
import numpy as np
|
7 |
-
from transformers import SegformerImageProcessor, SegformerForSemanticSegmentation
|
8 |
-
import cv2
|
9 |
-
import traceback
|
10 |
import os
|
11 |
|
12 |
-
|
13 |
-
os.environ['TOKENIZERS_PARALLELISM'] = 'false'
|
14 |
-
os.environ['TORCH_HOME'] = '/tmp/torch'
|
15 |
-
os.environ['HF_HOME'] = '/tmp/huggingface'
|
16 |
-
|
17 |
-
class RafayyVirtualTryOn:
|
18 |
def __init__(self):
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
except Exception as e:
|
75 |
-
print(f"Model initialization failed: {str(e)}")
|
76 |
-
raise
|
77 |
-
|
78 |
-
# Create Gradio interface with error handling
|
79 |
demo = gr.Interface(
|
80 |
-
fn=
|
81 |
-
inputs=
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
],
|
108 |
-
allow_flagging="never",
|
109 |
-
cache_examples=True
|
110 |
)
|
111 |
|
112 |
-
# Launch
|
113 |
if __name__ == "__main__":
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
enable_queue=True,
|
121 |
-
cache_examples=True,
|
122 |
-
max_threads=4
|
123 |
-
)
|
124 |
-
except Exception as e:
|
125 |
-
print(f"Launch failed: {str(e)}")
|
126 |
-
raise
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import os
|
3 |
|
4 |
+
class RafayyAIAssistant:
|
|
|
|
|
|
|
|
|
|
|
5 |
def __init__(self):
|
6 |
+
self.responses = {
|
7 |
+
"greeting": """π Welcome to Rafayy's Virtual Try-On Studio! How can I help you today?
|
8 |
+
|
9 |
+
β’ Type 'features' to learn about our services
|
10 |
+
β’ Type 'pricing' for subscription plans
|
11 |
+
β’ Type 'help' for usage tips
|
12 |
+
β’ Type 'contact' for support""",
|
13 |
+
|
14 |
+
"features": """β¨ Our AI-Powered Features:
|
15 |
+
|
16 |
+
1. Virtual Clothing Try-On
|
17 |
+
β’ Upload your photo
|
18 |
+
β’ Describe any clothing
|
19 |
+
β’ Get instant visualization
|
20 |
+
|
21 |
+
2. Professional Quality
|
22 |
+
β’ High-resolution output
|
23 |
+
β’ Realistic clothing rendering
|
24 |
+
β’ Advanced style controls
|
25 |
+
|
26 |
+
3. Easy to Use
|
27 |
+
β’ Simple interface
|
28 |
+
β’ Quick processing
|
29 |
+
β’ Multiple style options""",
|
30 |
+
|
31 |
+
"pricing": """π Subscription Plans:
|
32 |
+
|
33 |
+
1. Basic Plan - $9.99/month
|
34 |
+
β’ 100 try-ons per month
|
35 |
+
β’ Standard resolution
|
36 |
+
β’ Basic support
|
37 |
+
|
38 |
+
2. Pro Plan - $29.99/month
|
39 |
+
β’ 500 try-ons per month
|
40 |
+
β’ HD resolution
|
41 |
+
β’ Priority support
|
42 |
+
|
43 |
+
3. Enterprise Plan - Custom pricing
|
44 |
+
β’ Unlimited try-ons
|
45 |
+
β’ Ultra HD resolution
|
46 |
+
β’ Dedicated support""",
|
47 |
|
48 |
+
"help": """π Quick Tips:
|
49 |
+
|
50 |
+
1. For Best Results:
|
51 |
+
β’ Use clear, front-facing photos
|
52 |
+
β’ Ensure good lighting
|
53 |
+
β’ Wear fitted clothing
|
54 |
+
|
55 |
+
2. When Describing Clothes:
|
56 |
+
β’ Be specific about style
|
57 |
+
β’ Mention colors clearly
|
58 |
+
β’ Include design details
|
59 |
+
|
60 |
+
3. Troubleshooting:
|
61 |
+
β’ Retry if result isn't perfect
|
62 |
+
β’ Adjust style strength
|
63 |
+
β’ Check example prompts""",
|
64 |
|
65 |
+
"contact": """π§ Contact & Support:
|
66 |
+
|
67 |
+
β’ Email: support@rafayy.ai
|
68 |
+
β’ Hours: 24/7
|
69 |
+
β’ Response time: Within 24 hours
|
70 |
+
|
71 |
+
For immediate help, try our FAQ section or usage tips."""
|
72 |
+
}
|
73 |
+
|
74 |
+
def get_response(self, message):
|
75 |
+
"""Generate response based on user input"""
|
76 |
+
message = message.lower().strip()
|
77 |
+
|
78 |
+
# Check for keywords and return appropriate response
|
79 |
+
if message in ['hi', 'hello', 'hey', 'start']:
|
80 |
+
return self.responses["greeting"]
|
81 |
+
|
82 |
+
elif 'feature' in message or 'can' in message or 'what' in message:
|
83 |
+
return self.responses["features"]
|
84 |
+
|
85 |
+
elif 'price' in message or 'cost' in message or 'plan' in message:
|
86 |
+
return self.responses["pricing"]
|
87 |
+
|
88 |
+
elif 'help' in message or 'how' in message or 'tip' in message:
|
89 |
+
return self.responses["help"]
|
90 |
+
|
91 |
+
elif 'contact' in message or 'support' in message or 'email' in message:
|
92 |
+
return self.responses["contact"]
|
93 |
+
|
94 |
+
else:
|
95 |
+
return self.responses["greeting"]
|
96 |
+
|
97 |
+
# Initialize the chatbot
|
98 |
+
chatbot = RafayyAIAssistant()
|
99 |
+
|
100 |
+
# Create the Gradio interface
|
|
|
|
|
|
|
|
|
|
|
101 |
demo = gr.Interface(
|
102 |
+
fn=chatbot.get_response,
|
103 |
+
inputs=gr.Textbox(
|
104 |
+
placeholder="Ask me anything about Rafayy's Virtual Try-On Studio...",
|
105 |
+
label="Your Message"
|
106 |
+
),
|
107 |
+
outputs=gr.Textbox(
|
108 |
+
label="AI Assistant",
|
109 |
+
lines=10
|
110 |
+
),
|
111 |
+
title="π€ Rafayy AI Assistant",
|
112 |
+
description="""Welcome to Rafayy's Virtual Try-On Studio Support!
|
113 |
+
I'm here to help you with features, pricing, and usage tips.""",
|
114 |
+
theme="soft",
|
115 |
+
css="""
|
116 |
+
.gradio-container {
|
117 |
+
font-family: 'Arial', sans-serif;
|
118 |
+
}
|
119 |
+
.gr-button {
|
120 |
+
background: linear-gradient(45deg, #2193b0, #6dd5ed) !important;
|
121 |
+
border: none !important;
|
122 |
+
}
|
123 |
+
.gr-button:hover {
|
124 |
+
background: linear-gradient(45deg, #6dd5ed, #2193b0) !important;
|
125 |
+
transform: translateY(-2px);
|
126 |
+
transition: all 0.3s ease;
|
127 |
+
}
|
128 |
+
"""
|
|
|
|
|
|
|
129 |
)
|
130 |
|
131 |
+
# Launch the interface
|
132 |
if __name__ == "__main__":
|
133 |
+
demo.launch(
|
134 |
+
server_name="0.0.0.0",
|
135 |
+
server_port=7860,
|
136 |
+
share=False,
|
137 |
+
show_error=True
|
138 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|