abubasith86 commited on
Commit
1894d18
·
verified ·
1 Parent(s): 6fd7e42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -52
app.py CHANGED
@@ -1,52 +1,31 @@
1
- import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
- # Initialize the client with the updated model
5
- client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
6
-
7
- # Define the system prompt
8
- SYSTEM_PROMPT = (
9
- "You are Mohamed Abu Basith, an expert programming assistant specializing in software development, debugging, and code optimization. "
10
- "When addressing programming-related queries:\n"
11
- "- Provide clear, concise solutions with well-structured code examples in the appropriate language\n"
12
- "- Include detailed, step-by-step explanations of your reasoning and implementation\n"
13
- "- Prioritize efficient, production-ready code while explaining tradeoffs when relevant\n\n"
14
- "If asked about your identity, name, or 'what about you', respond exactly with: 'I am Mohamed Abu Basith.' "
15
- "For all other non-technical interactions, respond with a friendly, professional greeting "
16
- "avoiding technical jargon or programming-related content."
17
- )
18
-
19
- def respond(message, history: list[tuple[str, str]]):
20
- messages = [{"role": "system", "content": SYSTEM_PROMPT}]
21
-
22
- for user_msg, assistant_msg in history:
23
- if user_msg:
24
- messages.append({"role": "user", "content": user_msg})
25
- if assistant_msg:
26
- messages.append({"role": "assistant", "content": assistant_msg})
27
-
28
- messages.append({"role": "user", "content": message})
29
-
30
- response = ""
31
-
32
- # Static parameters for generation
33
- max_tokens = 512
34
- temperature = 0.7
35
- top_p = 0.95
36
-
37
- for token in client.chat_completion(
38
- messages,
39
- max_tokens=max_tokens,
40
- stream=True,
41
- temperature=temperature,
42
- top_p=top_p,
43
- ):
44
- content = token.choices[0].delta.content
45
- response += content
46
- yield response
47
-
48
- # Create the Gradio ChatInterface without additional inputs
49
- demo = gr.ChatInterface(respond)
50
-
51
- if __name__ == "__main__":
52
- demo.launch()
 
1
+ import os
2
+ import tempfile
3
+
4
+ from fastapi import FastAPI
5
+ from fastapi.responses import FileResponse
6
+
7
+ app = FastAPI()
8
+
9
+ MODEL_NAME = "Qwen/Qwen3-TTS-12Hz-0.6B-Base"
10
+
11
+ # Load the model here.
12
+ # Replace this section with the official Qwen code.
13
+
14
+ @app.get("/")
15
+ def health():
16
+ return {"status": "running"}
17
+
18
+ @app.get("/tts")
19
+ def generate(text: str):
20
+ output_file = tempfile.NamedTemporaryFile(
21
+ suffix=".wav",
22
+ delete=False
23
+ ).name
24
+
25
+ # Generate audio here.
26
+
27
+ return FileResponse(
28
+ output_file,
29
+ media_type="audio/wav",
30
+ filename="speech.wav",
31
+ )