Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import spaces
|
| 3 |
+
|
| 4 |
+
# Import the service - this should trigger GPU function registration
|
| 5 |
+
from minimal_service import service, generate_text_gpu
|
| 6 |
+
|
| 7 |
+
# Additional GPU function at app level for extra safety
|
| 8 |
+
@spaces.GPU
|
| 9 |
+
def app_gpu_test():
|
| 10 |
+
"""Test GPU function at app level"""
|
| 11 |
+
return "App GPU function works"
|
| 12 |
+
|
| 13 |
+
print("[App] GPU functions imported successfully")
|
| 14 |
+
print(f"[App] Service GPU function: {generate_text_gpu.__name__}")
|
| 15 |
+
print(f"[App] App GPU function: {app_gpu_test.__name__}")
|
| 16 |
+
|
| 17 |
+
def generate_response(user_input):
|
| 18 |
+
"""Generate response using the service"""
|
| 19 |
+
if not user_input.strip():
|
| 20 |
+
return "Please enter some text!"
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
response = service.generate(user_input)
|
| 24 |
+
return f"Generated: {response}"
|
| 25 |
+
except Exception as e:
|
| 26 |
+
return f"Error: {str(e)}"
|
| 27 |
+
|
| 28 |
+
# Create Gradio interface
|
| 29 |
+
with gr.Blocks(title="Minimal GPU Test") as demo:
|
| 30 |
+
gr.Markdown("# Minimal GPU Test")
|
| 31 |
+
gr.Markdown("This is a minimal test to check if Spaces GPU detection works.")
|
| 32 |
+
|
| 33 |
+
with gr.Row():
|
| 34 |
+
input_text = gr.Textbox(
|
| 35 |
+
label="Enter text",
|
| 36 |
+
placeholder="Type something...",
|
| 37 |
+
value="Hello, how are you?"
|
| 38 |
+
)
|
| 39 |
+
output_text = gr.Textbox(
|
| 40 |
+
label="Generated response",
|
| 41 |
+
interactive=False
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
generate_btn = gr.Button("Generate", variant="primary")
|
| 45 |
+
|
| 46 |
+
generate_btn.click(
|
| 47 |
+
fn=generate_response,
|
| 48 |
+
inputs=[input_text],
|
| 49 |
+
outputs=[output_text]
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
demo.launch()
|